Files
swift-log/Sources/TestApp/OneGlobalLoggerExample.swift
T
tomer doron bf76e03ea3 logger metadata support and unit tests
motivation: add tests to confirm desired functionality

changes:
* add property for logger metadata (aka context)
* improve pretty-metadata (aka pretty-context) generation
* add unit tests covering local and global use cases
* add [test only] implementation of MDC
* format with swiftformat

open issues:
* should we name the new property metadata or context
* should we include a default MDC implmentation as part of the logging API. if we dont, we will encourage libraries binding to specific logging implementations that support it (that was bad in java)
* tests are a bit brittle
* why is ExampleLoggerImplementation a reference type?
2018-12-03 18:32:51 -08:00

25 lines
795 B
Swift

import Foundation
import ServerLoggerAPI
// this model just uses one global logger. This is similar to what IBM's Logger API uses today (except that the one
// global thing has static methods.
let logger = LoggerFactory.make(identifier: "com.example.TestApp.OneGlobalLoggerExample")
enum OneGlobalLoggerExample {
static func main() {
for _ in 0 ..< 10 {
// NOTE: we can't change the log level per client because we only have one global logger
self.spawnFreshClient(uuid: UUID())
}
}
static func spawnFreshClient(uuid _: UUID) {
logger.info("we're up and running")
self.randomFunction()
}
static func randomFunction() {
logger.debug("just to say hi, here the log level / UUID do not get propagated")
}
}