1 module daemonize.log; 2 3 version(Have_dlogg) 4 { 5 import dlogg.log : LoggingLevel; 6 alias DaemonLogLevel = LoggingLevel; 7 } 8 else 9 { 10 /** 11 * Logging level options to control log output. 12 */ 13 enum DaemonLogLevel 14 { 15 Notice, 16 Warning, 17 Debug, 18 Fatal, 19 Muted 20 } 21 } 22 23 /** 24 * The interface to use to pass a logger reference into the daemon runner. 25 */ 26 synchronized interface IDaemonLogger 27 { 28 void logDebug(string message) nothrow; 29 void logInfo(lazy string message) nothrow; 30 void logWarning(lazy string message) nothrow; 31 void logError(lazy string message) @trusted nothrow; 32 DaemonLogLevel minLogLevel() @property; 33 void minLogLevel(DaemonLogLevel level) @property; 34 DaemonLogLevel minOutputLevel() @property; 35 void minOutputLevel(DaemonLogLevel level) @property; 36 void finalize() nothrow; 37 void reload(); 38 } 39 40 version(Have_dlogg) 41 { 42 /** 43 * Light wrapper around the Dlogg logger. 44 */ 45 synchronized class DloggLogger : IDaemonLogger 46 { 47 import dlogg.strict; 48 49 this(string filePath, StrictLogger.Mode mode = StrictLogger.Mode.Rewrite) @trusted 50 { 51 logger = new shared StrictLogger(filePath, mode); 52 } 53 54 void logDebug(string message) nothrow 55 { 56 logger.logDebug(message); 57 } 58 59 void logInfo(lazy string message) nothrow 60 { 61 logger.logInfo(message); 62 } 63 64 void logWarning(lazy string message) nothrow 65 { 66 logger.logWarning(message); 67 } 68 69 void logError(lazy string message) @trusted nothrow 70 { 71 logger.logError(message); 72 } 73 74 DaemonLogLevel minLogLevel() @property 75 { 76 return logger.minLoggingLevel; 77 } 78 79 void minLogLevel(DaemonLogLevel level) @property 80 { 81 logger.minLoggingLevel = level; 82 } 83 84 DaemonLogLevel minOutputLevel() @property 85 { 86 return logger.minOutputLevel; 87 } 88 89 void minOutputLevel(DaemonLogLevel level) @property 90 { 91 logger.minOutputLevel = level; 92 } 93 94 void finalize() @trusted nothrow 95 { 96 logger.finalize; 97 } 98 99 void reload() 100 { 101 logger.reload; 102 } 103 104 private StrictLogger logger; 105 } 106 }