It is simple logger layer written in Swift
struct Car {
let logger = Logger(Car.self)
func doSomething() {
logger.i("did something")
}
}By default it is configured to use print function (LocalLogStore).
You can add another log handler by implementing protocol LogStore and registering it to LoggerDispatcher.stores.append(...)
struct MyLogger: LogStore {
func log(_ level: LogLevel, _ tag: String, _ message: String) {
print("Simon says: \(message)")
}
}
LoggerDispatcher.stores.append(MyLogger())If you want to doscard all debug messages, set threshold to info:
LoggerDispatcher.logLevel = .infolet package = Package(
name: "SwiftApp",
dependencies: [
.package(url: "https://github.com/tomieq/Logger.git", .upToNextMajor(from: "1.2.0"))
],
targets: [dependencies.
.executableTarget(
name: "SwiftApp",
dependencies: [
.product(name: "Logger", package: "Logger")
]
),
],
// set mode 5 if run in Docker
swiftLanguageModes: [.v5]
)Disable buffering:
#if os(Linux)
import Glibc
#else
import Darwin
#endif
setvbuf(stdout, nil, _IONBF, 0)And it works only when compiling in Swift5 mode:
swiftLanguageModes: [.v5]