1 /** 2 * onyx-log: the generic, fast, multithreading logging library. 3 * 4 * User interface to work with logging. 5 * 6 * Copyright: © 2015 onyx-itdevelopment 7 * 8 * License: MIT license. License terms written in "LICENSE.txt" file 9 * 10 * Authors: Oleg Nykytenko (onyx), onyx.itdevelopment@gmail.com 11 * 12 * Version: 0.xx 13 * 14 * Date: 20.03.2015 15 */ 16 module onyx.log; 17 18 19 import onyx.bundle; 20 import onyx.core.logger; 21 22 23 @safe: 24 25 26 /** 27 * Create loggers 28 * 29 * Throws: BundleException, LogCreateException 30 */ 31 void createLoggers(immutable Bundle bundle) 32 { 33 create(bundle); 34 } 35 36 37 /** 38 * Get created logger interface to work with it 39 * 40 * Throws: LogException 41 */ 42 Log getLogger(immutable string loggerName) 43 { 44 return get(loggerName); 45 } 46 47 48 /** 49 * Delete logger 50 * 51 * Throws: Exception 52 */ 53 void deleteLogger(immutable string loggerName) 54 { 55 delete_([loggerName]); 56 } 57 58 59 60 /** 61 * Delete loggers 62 * 63 * Throws: Exception 64 */ 65 void deleteLoggers(immutable string[] loggerNames) 66 { 67 delete_(loggerNames); 68 } 69 70 71 /** 72 * Set path to file for save loggers exception information 73 * 74 * Throws: Exception 75 */ 76 void setErrFile(immutable string file) 77 { 78 setErrorFile(file); 79 } 80 81 82 /** 83 * User interface to work with logger. 84 */ 85 interface Log 86 { 87 88 /** 89 * Logger's name 90 */ 91 immutable (string) name(); 92 93 94 /** 95 * Configurations data 96 */ 97 immutable (Bundle) config(); 98 99 100 /** 101 * Logger's level 102 */ 103 immutable (string) level(); 104 105 106 /** 107 * Write message to logger 108 */ 109 void debug_(lazy const string msg) nothrow; 110 void info(lazy const string msg) nothrow; 111 void warning(lazy const string msg) nothrow; 112 void error(lazy const string msg) nothrow; 113 void critical(lazy const string msg) nothrow; 114 void fatal(lazy const string msg) nothrow; 115 } 116 117 118 119 /** 120 * Logger exception 121 */ 122 class LogException:Exception 123 { 124 @safe pure nothrow this(string exString) 125 { 126 super(exString); 127 } 128 } 129 130 131 /** 132 * Log creation exception 133 */ 134 class LogCreateException:LogException 135 { 136 @safe pure nothrow this(string exString) 137 { 138 super(exString); 139 } 140 } 141 142 143 144 @trusted: 145 unittest 146 { 147 auto bundle = new immutable Bundle("./test/test.conf"); 148 createLoggers(bundle); 149 setErrorFile("./log/error.log"); 150 151 // auto log = getLogger("ErrorLogger"); 152 // log.info("info msg"); 153 // log.error("error msg"); 154 155 version(vTestFile) 156 { 157 // auto log1 = getLogger("MainLogger"); 158 // log1.debug_("debug msg"); 159 // log1.info("info msg"); 160 // log1.error("error msg"); 161 162 auto log2 = getLogger("DebugLogger"); 163 log2.debug_("debug msg"); 164 log2.info("info msg"); 165 log2.error("error!!!!!! msg"); 166 } 167 }