Lightweight, pluggable, pure Swift logging library
You can install Log 📝 with SPM
- Add or amend a
Package.swift
- Add this dependency
.package(url: "https://github.com/dalu93/Log.git", from: "1.0.0")
- Then import
Log
in your code and start using it 🎉
log.error("something wrong happened")
Easy right? By default, Log comes with a set of
LogLevel
s which should cover, more or less, all the use
cases: debug
, info
, notice
, warning
and error
. It
also provides few utility methods that you can access as
below:
log.debug("message", isVerbose: true)
log.info("message")
log.notice("message")
log.warning("message")
log.error("message")
By using the default log
instance, your logs are going to
be sent to terminal output. If you want to change this
behavior, define your own Destination
by confirming to
LogDestination
protocol
struct LocalFileDestination: LogDestination {
func log(_ message: @autoclosure () -> String) {
// log to file here...
}
}
And then, initialize your own Logger
instance
let logger = Logger(
destinations: [
LocalFileDestination(),
TerminalDestination()
],
isVerbose: false
)
This code will send the logs to each LogDestination
which
is passed to the Logger
instance.