mirror of
https://github.com/apple/swift-log
synced 2026-11-28 04:14:20 +00:00
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
This commit is contained in:
1 parent
045ba36718
commit
c7583429a6
11 files changed
+47
-26
No files matched your search
@@ -4,13 +4,14 @@
|
||||
|
||||
import ExampleImplementation
|
||||
import Foundation
|
||||
import Logging
|
||||
@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.bootstrap({ ConfigLogHandler(label: $0, config: config) })
|
||||
LoggingSystem.bootstrapInternal({ ConfigLogHandler(label: $0, config: config) })
|
||||
|
||||
// run the example
|
||||
let logger = Logger(label: "com.example.TestApp")
|
||||
logger.trace("hello world?")
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// THIS IS NOT PART OF THE PITCH, JUST AN EXAMPLE HOW A LOGGER USAGE LOOKS LIKE
|
||||
//
|
||||
|
||||
import ExampleImplementation
|
||||
import Foundation
|
||||
import Logging
|
||||
|
||||
@@ -11,8 +10,6 @@ import Logging
|
||||
// we also allow users to set metadata on the context object and reuse that as the metadata for logging
|
||||
enum ContextBasedSystem {
|
||||
static func main() {
|
||||
// boostrap with our sample implementation
|
||||
LoggingSystem.bootstrap(SimpleLogHandler.init)
|
||||
// run the example
|
||||
for i in 1 ... 2 {
|
||||
print("---------------------------- processing request #\(i) ----------------------------")
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// THIS IS NOT PART OF THE PITCH, JUST AN EXAMPLE HOW A LOGGER USAGE LOOKS LIKE
|
||||
//
|
||||
|
||||
import ExampleImplementation
|
||||
import Foundation
|
||||
import Logging
|
||||
|
||||
@@ -25,8 +24,6 @@ var logger: Logger {
|
||||
// this is a contrived example of a system that shares one global logger
|
||||
enum GlobalLoggerBasedSystem {
|
||||
static func main() {
|
||||
// boostrap with our sample implementation
|
||||
LoggingSystem.bootstrap(SimpleLogHandler.init)
|
||||
// run the example
|
||||
for i in 1 ... 2 {
|
||||
print("---------------------------- processing request #\(i) ----------------------------")
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
// THIS IS NOT PART OF THE PITCH, JUST AN EXAMPLE HOW A LOGGER USAGE LOOKS LIKE
|
||||
//
|
||||
|
||||
import ExampleImplementation
|
||||
import Foundation
|
||||
import Logging
|
||||
|
||||
// this is a contrived example of a system where each component obtain its own logger
|
||||
enum LocalLoggerBasedSystem {
|
||||
static func main() {
|
||||
// boostrap with our sample implementation
|
||||
LoggingSystem.bootstrap(SimpleLogHandler.init)
|
||||
// run the example
|
||||
for i in 1 ... 2 {
|
||||
print("---------------------------- processing request #\(i) ----------------------------")
|
||||
|
||||
@@ -4,12 +4,13 @@
|
||||
|
||||
import ExampleImplementation
|
||||
import Foundation
|
||||
import Logging
|
||||
@testable import Logging // need access to internal bootstrap function
|
||||
|
||||
enum MultiplexExample {
|
||||
static func main() {
|
||||
// boostrap with two of our sample implementations
|
||||
LoggingSystem.bootstrap({ MultiplexLogHandler([SimpleLogHandler(label: $0), FileLogHandler(label: $0)]) })
|
||||
LoggingSystem.bootstrapInternal({ MultiplexLogHandler([SimpleLogHandler(label: $0), FileLogHandler(label: $0)]) })
|
||||
|
||||
// run the example
|
||||
let logger = Logger(label: "com.example.TestApp")
|
||||
logger.info("hello world!")
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import Logging
|
||||
import ExampleImplementation
|
||||
|
||||
// boostrap with our sample implementation
|
||||
LoggingSystem.bootstrap(SimpleLogHandler.init)
|
||||
|
||||
print()
|
||||
print("##### global logger based system #####")
|
||||
GlobalLoggerBasedSystem.main()
|
||||
|
||||
Reference in new issue
Block a user