Skip to content

InchStudio/ExtendedLogging

Repository files navigation

📘 ExtendedLogging

Build Status Swift 5.3 Swift Package Manager Platforms OS X | Linux

Library provides additional LogHandlers for Swift Loggig system. Log hander can write information into file. You can chose one of following formatters:

  • SingleLineFormatter - writes each log as single plain line in file,
  • JsonFormatter - writes each log as JSON data.

Getting started

You need to add library to Package.swift file:

  • add package to dependencies:
.package(url: "https://github.com/Mikroservices/ExtendedLogging.git", from: "1.0.0")
  • and add product to your target:
.target(name: "App", dependencies: [
    .product(name: "Vapor", package: "vapor"),
    .product(name: "ExtendedLogging", package: "ExtendedLogging")
])

Then you can add log hander to Logging system:

LoggingSystem.bootstrap { label -> LogHandler in
    FileLogger(label: label, path: "tests01.log", level: .debug)
}

Also you can combine multiple LogHandlers:

LoggingSystem.bootstrap { label -> LogHandler in
    MultiplexLogHandler([
        ConsoleLogger(label: label, console: Terminal(), level: .debug),
        FileLogger(label: label,
                   path: "Logs/emails.log",
                   level: .debug,
                   logFormatter: JsonFormatter(),
                   rollingInterval: .month, 
                   fileSizeLimitBytes: 10485760
        )
    ])
}

And now you can use stadard logging system to log information:

let logger = Logger(label: "mikroservices.mczachurski.dev")
logger.info("Hello World!")

Some frameworks creates Logger for you. For example in Vapor you should initialize LoggingSystem at the top of main.swift file and use it in your application like this:

request.logger.info("Hello World!")

Developing

Download the source code and run in command line:

$ git clone https://github.com/Mikroservices/ExtendedLogging.git
$ swift package update
$ swift build

Run the following command if you want to open project in Xcode:

$ open Package.swift

Contributing

You can fork and clone repository. Do your changes and pull a request.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages