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