Files
swift-log/Sources/ExampleUsage/ConfigExample.swift
T
tomer doron c7583429a6 enforce that logging system can only be bootstrapped once (#32)
motivation: safer logging system

changes: do a precondition check to verify logging syste is only initialized/bootstrapped once per process
2019-02-22 18:13:52 +00:00

23 lines
809 B
Swift

//
// THIS IS NOT PART OF THE PITCH, JUST AN EXAMPLE HOW A LOGGER USAGE LOOKS LIKE
//
import ExampleImplementation
import Foundation
@testable import Logging // need access to internal bootstrap function
enum ConfigExample {
static func main() {
// boostrap with our config based sample implementations
let config = Config(defaultLogLevel: .info)
LoggingSystem.bootstrapInternal({ ConfigLogHandler(label: $0, config: config) })
// run the example
let logger = Logger(label: "com.example.TestApp")
logger.trace("hello world?")
// changes the config in runtime, real implemnetations will use config files instead of in-memory config
config.set(key: "com.example.TestApp", value: .trace)
logger.trace("hello world!")
}
}