HeliumLogger
public class HeliumLogger
extension HeliumLogger : Logger
A lightweight implementation of the LoggerAPI protocol.
-
A Boolean value that indicates whether the logger output should be colorized.
Usage Example:
The logger is set up to log
verboselevel messages (this is the default) and all levels below, that is, it will show messages of typeverbose,info,warninganderror.let logger = HeliumLogger() logger.colored = true Log.logger = logger Log.error("This message will be red when your application is run in the terminal.")Declaration
Swift
public var colored: Bool -
A Boolean value indicating whether to use the detailed logging format when a user logging format is not specified.
Declaration
Swift
public var details: Bool -
A Boolean value indicating whether to include SwiftLog metadata in the logging format when a user logging format is not specified.
Declaration
Swift
public var includeMetadata: Bool -
A Boolean value indicating whether to include SwiftLog label in the logging format when a user logging format is not specified.
Declaration
Swift
public var includeLabel: Bool -
A Boolean value indicating whether to use the full file path, or just the filename.
Declaration
Swift
public var fullFilePath: Bool -
The user specified logging format, if
formatis notnil.For example: “[(%date)] [(%label)] [(%type)] (%file):(%line) (%func)”.
Declaration
Swift
public var format: String? { get set } -
The format used when adding the date and time to logged messages, if
dateFormatis notnil.Declaration
Swift
public var dateFormat: String? { get set } -
The timezone used in the date time format, if
timeZoneis notnil.Declaration
Swift
public var timeZone: TimeZone? { get set } -
Default date format - ISO 8601.
Declaration
Swift
public static let defaultDateFormat: String -
Create a
HeliumLoggerinstance and set it up as the logger used by theLoggerAPIprotocol.Usage Example:
In the default case, the logger is set up to log
verboselevel messages and all levels below, that is, it will show messages of typeverbose,info,warninganderror.HeliumLogger.use()In the following example, the logger is set up to log
warninglevel messages and all levels below, i.e. it will show messages of typewarninganderror.HeliumLogger.use(.warning)Declaration
Swift
public class func use(_ type: LoggerMessageType = .verbose)Parameters
typeThe most detailed message type (
LoggerMessageType) to see in the output of the logger. Defaults toverbose. -
Create a
HeliumLoggerinstance.Declaration
Swift
public init(_ type: LoggerMessageType = .verbose)Parameters
typeThe most detailed message type (
LoggerMessageType) to see in the output of the logger. Defaults toverbose. -
A one-time configuration function to bootstrap the SwiftLog logging system using
HeliumLoggeras the logging backend.Usage Example:
This bootstraps the SwiftLog logging system with a default
HeliumLoggerinstance. The defaultHeliumLoggerinstance will be used as the logging backend for SwiftLog.HeliumLogger.bootstrapSwiftLog()It’s also possible to customize the default
HeliumLoggerinstance using a configuration closure.HeliumLogger.bootstrapSwiftLog { heliumLogger in heliumLogger.colored = true }Declaration
Swift
public static func bootstrapSwiftLog(_ configure: ((HeliumLogger) -> Void)? = nil)Parameters
configureAn optional closure that may be used to configure the default
HeliumLoggerinstance. -
Creates a
HeliumLogHandlerinstance for use with the SwiftLog logging system.Usage Example:
This may be used to bootstrap the SwiftLog logging system with a
HeliumLoggerinstance. TheHeliumLoggerinstance will be used as the logging backend for SwiftLog.let heliumLogger = HeliumLogger() LoggingSystem.bootstrap(heliumLogger.makeLogHandler)Declaration
Swift
public func makeLogHandler(label: String) -> HeliumLogHandlerParameters
labelThe label to use for a SwiftLog
Logger. -
Creates a
HeliumLogHandlerinstance for use with the SwiftLog logging system.Usage Example:
This may be used to bootstrap the SwiftLog logging system with a default
HeliumLoggerinstance. The defaultHeliumLoggerinstance will be used as the logging backend for SwiftLog.LoggingSystem.bootstrap(HeliumLogger.makeLogHandler)Declaration
Swift
public static func makeLogHandler(label: String) -> HeliumLogHandlerParameters
labelThe label to use for a SwiftLog
Logger. -
Output a logged message.
Declaration
Swift
public func log(_ type: LoggerMessageType, msg: String, functionName: String, lineNum: Int, fileName: String )Parameters
typeThe type of the message (
LoggerMessageType) being logged.msgThe message to be logged.
functionNameThe name of the function invoking the logger API.
lineNumThe line in the source code of the function invoking the logger API.
fileNameThe file containing the source code of the function invoking the logger API.
-
Indicates if a message with a specified type (
LoggerMessageType) will be in the logger output (i.e. will not be filtered out).Usage Example:
The logger is set up to log
warninglevel messages and all levels below, that is, it will show messages of typewarninganderror. This means averboselevel message will not be displayed.let logger = HeliumLogger(.warning) Log.logger = logger logger.isLogging(.warning) // Returns true logger.isLogging(.verbose) // Returns falseDeclaration
Swift
public func isLogging(_ type: LoggerMessageType) -> BoolParameters
typeThe type of message (
LoggerMessageType).Return Value
A Boolean indicating whether a message of the specified type (
LoggerMessageType) will be in the logger output.
View on GitHub
HeliumLogger Class Reference