@@ -34,17 +34,23 @@ version(Have_vibe_core) {
34
34
alias logError = vibe.core.log.logError ;
35
35
alias logCritical = vibe.core.log.logCritical ;
36
36
// 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
+ }
48
54
49
55
unittest {
50
56
version (Have_vibe_core) {
@@ -59,18 +65,18 @@ unittest {
59
65
logError(" Test that a call to mysql.logger.logError maps to vibe.core.log.logError" );
60
66
logCritical(" Test that a call to mysql.logger.logCritical maps to vibe.core.log.logCritical" );
61
67
// 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 {
63
69
// Checks that when using std.experimental.logger the log entry is correct.
64
70
// This test kicks in when commenting out the 'vibe-core' dependency and running 'dub test', although
65
71
// not ideal if vibe-core is availble the logging goes through vibe anyway.
66
72
// Output can be seen in terminal when running 'dub test'.
67
- import std.experimental.logger : Logger, LogLevel, sharedLog;
68
73
import std.stdio : writeln, writefln;
69
74
import std.conv : to;
70
75
71
76
writeln(" Running the logger tests using (std.experimental.logger)" );
77
+ alias LogLevel = stdlog.LogLevel;
72
78
73
- class TestLogger : Logger {
79
+ class TestLogger : stdlog . Logger {
74
80
LogLevel logLevel;
75
81
string file;
76
82
string moduleName;
@@ -91,7 +97,12 @@ unittest {
91
97
}
92
98
93
99
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;
95
106
96
107
// check that the various log alias functions get the expected results
97
108
logDebug(" This is a TRACE message" );
0 commit comments