A logger protocol that provides a common logging interface for different kinds of loggers. In addition, a class with a set of static functions for logging within your code is provided.
Kitura uses this API throughout its implementation when logging.
LoggerAPI package to the dependencies within your application’s
Package.swift file. Substitute
"x.x.x" with the latest
.package(url: "https://github.com/IBM-Swift/LoggerAPI.git", from: "x.x.x")
LoggerAPI to your target's dependencies:
.target(name: "example", dependencies: ["LoggerAPI"]),
Add log messages to your application:
Log.warning("This is a warning.") Log.error("This is an error.")
Define a logger
You need to define a
logger in order to output these messages. You may wish to write your own
Logger implementation, or you can use
HeliumLogger that writes to standard output:
import LoggerAPI import HeliumLogger let myLogger = HeliumLogger(.info) Log.logger = myLogger
You can find out more about HeliumLogger here.
Logging messages to swift-log
You can direct your log messages to be logged via swift-log by setting the
import LoggerAPI import Logging let myLogger = Logging.Logger(label: "myLogger") myLogger.logLevel = .notice Log.swiftLogger = myLogger
swiftLogger are set, then log messages will be sent to both logging backends. The log level configured for a LoggerAPI Logger and a swift-log Logger are independent, so may be used to log at different levels.
Note that because the hierarchy of log levels defined by LoggerAPI and swift-log is slightly different, a mapping is defined between the levels. See the documentation for
Log.isLogging() for details.
For more information visit our API reference.
We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
You may find interesting
1.9.0 - 2019-06-06 12:55:12
- feat: Adopt swift-log (#47)
It is now possible to direct LoggerAPI log messages to a
Logging.Logger provided by swift-log, instead of or in addition to an existing
LoggerAPI now depends upon swift-log in order to provide this facility. This does not change the behavior of existing applications.
- access to
Log.swiftLoggeris now thread-safe (#47)
1.8.1 - 2019-04-04 11:18:32
- Support Swift 5
1.8.0 - 2018-11-26 16:34:45
- Add support for building with Swift 5 (#41)
- Drop support for Swift 3.
Note: if you require Swift 3 support, please continue to use the 1.7 release of LoggerAPI.
1.7.3 - 2018-02-27 16:53:33
- Support Swift 4.1
1.7.1 - 2017-08-31 15:45:26
- Add support for Swift 4
0.10.0 - 2016-08-08 08:48:11
New isLogging() API to check current log level
- 2016-07-29 11:11:53
Updates to low level APIs to make the code more Swifty
v0.3.0 - 2016-04-17 19:08:25
- 2016-04-17 19:08:06
v0.4.0 - 2016-03-08 23:10:01
v0.2.0 - 2016-02-19 22:35:29
- Defines a logger protocol for Logger implementations.