HeliumLogger
Provides a lightweight Swift Logging framework.
Features:
- Different logging levels such as Warning, Verbose, and Error
- Color output to terminal
Usage:
- Import
HeliumLogger
andLoggerAPI
:
import HeliumLogger
import LoggerAPI
- Initialize an instance of
HeliumLogger
. Set it as the logger used byLoggerAPI
.
let logger = HeliumLogger()
Log.logger = logger
or if you don't need to customize HeliumLogger
:
HeliumLogger.use()
-
You can specify the level of output on initialization. You will see output of that level, and all levels below that. The order goes:
- entry (entering a function)
- exit (exiting a function)
- debug
- verbose (default)
- info
- warning
- error
So for example,
let logger = HeliumLogger(.verbose)
Log.logger = logger
Will show messages of verbose
, info
, warning
, and error
type.
While,
HeliumLogger.use(.warning)
will only show messages of warning
and error
type.
- Adjust logging levels at runtime:
Calling HeliumLogger.use(LoggerMessageType)
will set the LoggerAPI to use this new HeliumLogger instance. This allows you to, for example, if in a route you detect an error with your application, dynamically increase the log level.
This new instance will not have any customization you did to other instances. (see list item 6).
- Logging messages:
Log.verbose("This is a verbose log message.")
Log.info("This is an informational log message.")
Log.warning("This is a warning.")
Log.error("This is an error.")
Log.debug("This is a debug message.")
- Further customization:
/// Whether, if true, or not the logger output should be colorized.
public var colored: Bool = false
/// If true, use the detailed format when a user logging format wasn't specified.
public var details: Bool = true
/// If true, use the full file path, not just the filename.
public var fullFilePath: Bool = false
/// If not nil, specifies the user specified logging format.
/// For example: "[(%date)] [(%type)] [(%file):(%line) (%func)] (%msg)"
public var format: String?
/// If not nil, specifies the format used when adding the date and the time to the logged messages
public var dateFormat: String?
/// If not nil, specifies the timezone used in the date time format
public var timeZone: TimeZone?