@@ -34,17 +34,23 @@ version(Have_vibe_core) {
3434 alias logError = vibe.core.log.logError ;
3535 alias logCritical = vibe.core.log.logCritical ;
3636 // alias logFatal = vibe.core.log.logFatal;
37- } else static if (__traits(compiles, (){ import std.experimental.logger ; } )) {
38- import std.experimental.logger ;
39-
40- alias logTrace = std.experimental.logger.tracef ;
41- alias logDebug = std.experimental.logger.tracef ; // no debug level in std.experimental.logger but arguably trace/debug/verbose all mean the same
42- alias logInfo = std.experimental.logger.infof ;
43- alias logWarn = std.experimental.logger.warningf ;
44- alias logError = std.experimental.logger.errorf ;
45- alias logCritical = std.experimental.logger.criticalf ;
46- // alias logFatal = std.experimental.logger.fatalf;
47- } else static assert (false );
37+ } else {
38+ static if (__traits(compiles, (){ import std.experimental.logger ; } )) {
39+ import stdlog = std.experimental.logger ;
40+ } else static if (__traits(compiles, (){ import std.logger ; })) {
41+ import stdlog = std.logger ;
42+ } else {
43+ static assert (false , " no std.logger detected" );
44+ }
45+
46+ alias logTrace = stdlog.tracef;
47+ alias logDebug = stdlog.tracef; // no debug level in stdlog but arguably trace/debug/verbose all mean the same
48+ alias logInfo = stdlog.infof;
49+ alias logWarn = stdlog.warningf;
50+ alias logError = stdlog.errorf;
51+ alias logCritical = stdlog.criticalf;
52+ // alias logFatal = stdlog.fatalf;
53+ }
4854
4955unittest {
5056 version (Have_vibe_core) {
@@ -59,18 +65,18 @@ unittest {
5965 logError(" Test that a call to mysql.logger.logError maps to vibe.core.log.logError" );
6066 logCritical(" Test that a call to mysql.logger.logCritical maps to vibe.core.log.logCritical" );
6167 // logFatal("Test that a call to mysql.logger.logFatal maps to vibe.core.log.logFatal");
62- } else static if (__traits(compiles, (){ import std.experimental.logger ; } )) {
68+ } else {
6369 // Checks that when using std.experimental.logger the log entry is correct.
6470 // This test kicks in when commenting out the 'vibe-core' dependency and running 'dub test', although
6571 // not ideal if vibe-core is availble the logging goes through vibe anyway.
6672 // Output can be seen in terminal when running 'dub test'.
67- import std.experimental.logger : Logger, LogLevel, sharedLog;
6873 import std.stdio : writeln, writefln;
6974 import std.conv : to;
7075
7176 writeln(" Running the logger tests using (std.experimental.logger)" );
77+ alias LogLevel = stdlog.LogLevel;
7278
73- class TestLogger : Logger {
79+ class TestLogger : stdlog . Logger {
7480 LogLevel logLevel;
7581 string file;
7682 string moduleName;
@@ -91,7 +97,12 @@ unittest {
9197 }
9298
9399 auto logger = new TestLogger(LogLevel.all);
94- sharedLog = logger;
100+ // handle differences between std.experimental.logger and std.logger
101+ alias LogType = typeof (stdlog.sharedLog());
102+ static if (is (LogType == shared ))
103+ stdlog.sharedLog = (() @trusted => cast (shared )logger)();
104+ else
105+ stdlog.sharedLog = logger;
95106
96107 // check that the various log alias functions get the expected results
97108 logDebug(" This is a TRACE message" );
0 commit comments