Skip to content

Commit 736a758

Browse files
committed
logger should have error level logging too
1 parent 108c476 commit 736a758

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Sources/JExtractSwiftLib/Logger.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ public struct Logger {
2727
self.logLevel = logLevel
2828
}
2929

30+
public func error(
31+
_ message: @autoclosure () -> String,
32+
metadata: [String: Any] = [:],
33+
file: String = #fileID,
34+
line: UInt = #line,
35+
function: String = #function
36+
) {
37+
guard logLevel <= .error else {
38+
return
39+
}
40+
41+
let metadataString: String =
42+
if metadata.isEmpty { "" } else { "\(metadata)" }
43+
44+
print("[error][\(file):\(line)](\(function)) \(message()) \(metadataString)")
45+
}
46+
3047
public func warning(
3148
_ message: @autoclosure () -> String,
3249
metadata: [String: Any] = [:],

0 commit comments

Comments
 (0)