1 /** 2 * onyx-log: the generic, fast, multithreading logging library. 3 * 4 * User interface to work with logging. 5 * 6 * Copyright: © 2015- Oleg Nykytenko 7 * License: MIT license. License terms written in "LICENSE.txt" file 8 * Authors: Oleg Nykytenko, oleg.nykytenko@gmail.com 9 */ 10 11 module onyx.log; 12 13 14 import onyx.bundle; 15 public import onyx.core.logger; 16 17 18 deprecated("Use onyx.log.Logger") 19 alias Log = Logger; 20 21 @safe: 22 23 /** 24 * Create loggers from config bundle 25 * 26 * Throws: BundleException, LogCreateException 27 */ 28 void createLoggers(immutable Bundle bundle) 29 { 30 create(bundle); 31 } 32 33 /** 34 * Get created logger interface to work with it 35 * 36 * Throws: LogException 37 */ 38 Logger getLogger(immutable string loggerName) 39 { 40 return get(loggerName); 41 } 42 43 /** 44 * Delete logger 45 * 46 * Throws: Exception 47 */ 48 void deleteLogger(immutable string loggerName) 49 { 50 delete_([loggerName]); 51 } 52 53 /** 54 * Delete loggers 55 * 56 * Throws: Exception 57 */ 58 void deleteLoggers(immutable string[] loggerNames) 59 { 60 delete_(loggerNames); 61 } 62 63 /** 64 * Check is Logger present 65 */ 66 bool isLogger(immutable string loggerName) nothrow 67 { 68 return isCreated(loggerName); 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 /** 84 * Logger exception 85 */ 86 class LogException:Exception 87 { 88 @safe pure nothrow this(string exString) 89 { 90 super(exString); 91 } 92 } 93 94 /** 95 * Log creation exception 96 */ 97 class LogCreateException:LogException 98 { 99 @safe pure nothrow this(string exString) 100 { 101 super(exString); 102 } 103 } 104 105 106 107 unittest 108 { 109 auto bundle = new immutable Bundle("./test/test.conf"); 110 createLoggers(bundle); 111 setErrorFile("./log/error.log"); 112 113 version(vTestFile) 114 { 115 auto log2 = getLogger("DebugLogger"); 116 log2.debug_("debug msg"); 117 log2.info("info msg %d", 2); 118 log2.error("error test %d %s", 3, "msg"); 119 } 120 else 121 { 122 Logger log = getLogger("ErrorLogger"); 123 log.info("info test msg %d", 2); 124 log.error("error test %s", "msg"); 125 log.critical("critical test msg %#x", 125); 126 } 127 }