-
Notifications
You must be signed in to change notification settings - Fork 109
/
Log.swift
45 lines (41 loc) · 1.16 KB
/
Log.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Log.swift
// TinodeSDK
//
// Copyright © 2019 Tinode. All rights reserved.
//
import Foundation
enum LogType {
case debug
case info
case error
case fault
}
open class Log {
let prefix: String
public static let `default` = Log(subsystem: "default")
public init(subsystem: String = Bundle.main.bundleIdentifier ?? "") {
self.prefix = "[" + subsystem + "] "
}
func log(type: LogType, message: StaticString, _ args: [CVarArg]) {
#if !DEBUG
guard type != .debug else { return }
#endif
let msg = self.prefix + message.description
withVaList(args) {
NSLogv(msg, $0)
}
}
public func debug(_ message: StaticString, _ args: CVarArg...) {
log(type: .debug, message: message, args)
}
public func info(_ message: StaticString, _ args: CVarArg...) {
log(type: .info, message: message, args)
}
public func error(_ message: StaticString, _ args: CVarArg...) {
log(type: .error, message: message, args)
}
public func fault(_ message: StaticString, _ args: CVarArg...) {
log(type: .fault, message: message, args)
}
}