Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logger

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())

Logging threshold

If you want to doscard all debug messages, set threshold to info:

LoggerDispatcher.logLevel = .info

Swift Package Manager

let 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]
)

Logging in Docker

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]

About

Simple logger layer

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages