mirror of
https://github.com/apple/swift-log
synced 2026-11-28 04:14:20 +00:00
naming proposal (#2)
* naming proposal motivation: intuitive APIs changes: * Logger is the main API users interact with * Logging is the factory from which users get instances of Logger, via Logging.for(identifer) * LogHandler is what logging libraries implement, this is not exposed to users as its boxed in Logger * replace Logging (aka LoggerFactory) factory property with bootstrap(factory) function * rename main module to Logging since its not server only * converge examples into an Examples module open questions: * Logging.make or Logging.for * is Logging.for(object: Any.Type) a good idea? is there a better way to get the FQN for an object?
This commit is contained in:
1 parent
a4cb92d526
commit
b5dcb3140e
12 files changed
+80
-91
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import Foundation
|
||||
import Logging
|
||||
|
||||
private class Client {
|
||||
func spawnFreshClient(uuid: UUID, logger: Logger) {
|
||||
var logger = logger
|
||||
logger[diagnosticKey: "UUID"] = uuid.description
|
||||
logger.info("we're up and running")
|
||||
let otherSubSystem = OtherSubSystem()
|
||||
otherSubSystem.randomFunction(logger: logger)
|
||||
logger.debug("random function returned")
|
||||
}
|
||||
}
|
||||
|
||||
private class OtherSubSystem {
|
||||
func randomFunction(logger: Logger) {
|
||||
logger.debug("this propagates UUID and log level")
|
||||
}
|
||||
}
|
||||
|
||||
enum ExplicitContextPassingExample {
|
||||
static func main() {
|
||||
let logger = Logging.make("com.example.TestApp.ExplicitContextPassingExample.main")
|
||||
for clientID in 0 ..< 10 {
|
||||
var clientLogger = logger
|
||||
if clientID % 3 == 0 {
|
||||
clientLogger.logLevel = .debug
|
||||
} else {
|
||||
clientLogger.logLevel = .info
|
||||
}
|
||||
Client().spawnFreshClient(uuid: UUID(), logger: clientLogger)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user