|
| 1 | +/** |
| 2 | + * Tae Won Ha - http://taewon.de - @hataewon |
| 3 | + * See LICENSE |
| 4 | + */ |
| 5 | + |
| 6 | +import Foundation |
| 7 | +import os |
| 8 | + |
| 9 | +public extension Logger { |
| 10 | + func trace( |
| 11 | + file: String = #file, |
| 12 | + function: String = #function, |
| 13 | + line: Int = #line, |
| 14 | + _ msg: some Any |
| 15 | + ) { |
| 16 | + #if TRACE |
| 17 | + let message = "[\((file as NSString).lastPathComponent) - \(function):\(line)] [TRACE] \(msg)" |
| 18 | + self.log(level: .debug, "\(message)") |
| 19 | + #endif |
| 20 | + } |
| 21 | + |
| 22 | + func debug( |
| 23 | + file: String = #file, |
| 24 | + function: String = #function, |
| 25 | + line: Int = #line |
| 26 | + ) { |
| 27 | + #if DEBUG |
| 28 | + let message = "[\((file as NSString).lastPathComponent) - \(function):\(line)]" |
| 29 | + self.log(level: .debug, "\(message)") |
| 30 | + #endif |
| 31 | + } |
| 32 | + |
| 33 | + func debug( |
| 34 | + file: String = #file, |
| 35 | + function: String = #function, |
| 36 | + line: Int = #line, |
| 37 | + _ msg: some Any |
| 38 | + ) { |
| 39 | + #if DEBUG |
| 40 | + let message = "[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)" |
| 41 | + self.log(level: .debug, "\(message)") |
| 42 | + #endif |
| 43 | + } |
| 44 | + |
| 45 | + func info( |
| 46 | + file: String = #file, |
| 47 | + function: String = #function, |
| 48 | + line: Int = #line, |
| 49 | + _ msg: some Any |
| 50 | + ) { |
| 51 | + let message = "[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)" |
| 52 | + self.log(level: .info, "\(message)") |
| 53 | + } |
| 54 | + |
| 55 | + func error( |
| 56 | + file: String = #file, |
| 57 | + function: String = #function, |
| 58 | + line: Int = #line, |
| 59 | + _ msg: some Any |
| 60 | + ) { |
| 61 | + let message = "[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)" |
| 62 | + self.log(level: .error, "\(message)") |
| 63 | + } |
| 64 | + |
| 65 | + func fault( |
| 66 | + file: String = #file, |
| 67 | + function: String = #function, |
| 68 | + line: Int = #line, |
| 69 | + _ msg: some Any |
| 70 | + ) { |
| 71 | + let message = "[\((file as NSString).lastPathComponent) - \(function):\(line)] \(msg)" |
| 72 | + self.log(level: .fault, "\(message)") |
| 73 | + } |
| 74 | +} |
0 commit comments