Logger
public class Logger
Logger; a small logging framework to help you debug your app and filter your logs
-
Determines whether or not the logger is enabled
Declaration
Swift
public var enabled: Bool = true
-
Sets the minimum log level of the logger.
Declaration
Swift
public var minLevel: LogLevel
-
Sets the terminator of a log line in the console.
Declaration
Swift
public var terminator: String = "\n"
-
Sets the separator of elements in the log message.
Declaration
Swift
public var separator: String = ", "
-
Sets how the log message should be formatted. See the class for more info.
Declaration
Swift
public var logFormat: LogFormat
-
More useful for testing purposes; will perform the log to a pipe or console on the current thread
Declaration
Swift
public var useCurrentThread: Bool = false
-
Sets the pipe used for output. Default (nil) refers to the console
Declaration
Swift
public var pipe: NSPipe?
-
The shared instance of the Logger preventing the user from needing to create a new instance of
Logger
everytime that a message should be loggedDeclaration
Swift
public static var shared = Logger()
-
Creates an instance of the
Logger
class - Parameter minLevel: The minimum log level of the logger. SeeLogger+LogLevels
for more info - Parameter logFormat: The format in which the log message should be generatedDeclaration
Parameters
minLevel
The minimum log level of the logger. See
Logger+LogLevels
for more infologFormat
The format in which the log message should be generated
-
Registers the file of the caller to a specific minimum log level - Parameter level: the minimum log level to be associated with the file - Parameter filePath: Should not be overwritten. It’s used to determine the filename of the caller
Declaration
Swift
public func registerFile(level: LogLevel, filePath: String = #file)
Parameters
level
the minimum log level to be associated with the file
filePath
. It’s used to determine the filename of the caller
-
Logs a message with a specific log level - Parameter level: The minimum log level to be associated with the message - Parameter message: A series of objects to be logged - Parameter filePath: Determines the file path of the caller - Parameter line: Determines the line in the source code of the caller - Parameter column: Determines the column in the source code of the caller - Parameter function: Determines the function that triggered the call
Declaration
Swift
public func log(level: LogLevel, message: [CVarArgType], filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
level
The minimum log level to be associated with the message
message
A series of objects to be logged
filePath
Determines the file path of the caller
line
Determines the line in the source code of the caller
column
Determines the column in the source code of the caller
function
Determines the function that triggered the call
-
Triggers a log with under the debug log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public func debug(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the trace log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public func trace(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the info log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public func info(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the warn log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public func warn(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the error log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public func error(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the fatal log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public func fatal(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
See https://logging.apache.org/log4j/2.0/manual/architecture.html for more info
- ALL: All levels including custom levels.
- DEBUG: Designates fine-grained informational events that are most useful to debug an application.
- ERROR: Designates error events that might still allow the application to continue running.
- FATAL: Designates very severe error events that will presumably lead the application to abort.
- INFO: Designates informational messages that highlight the progress of the application at coarse-grained level.
- OFF: The highest possible rank and is intended to turn off logging.
- TRACE: Designates finer-grained informational events than the DEBUG.
- WARN: Designates potentially harmful situations.
ALL < DEBUG < TRACE < INFO < WARN < ERROR < FATAL < OFF.
A log request of level p in a logger with level q is enabled if p >= q
See moreDeclaration
Swift
public enum LogLevel: Int, CustomStringConvertible
-
Sets the format of the global logger - Parameter format: The specific LogFormat to be used. Defaults to
LogFormat.defaultLogFormat
Parameters
format
The specific LogFormat to be used. Defaults to
LogFormat.defaultLogFormat
-
Enables/disables the global logger. - Parameter enabled:
TRUE
to enable,FALSE
to disable.Declaration
Swift
public class func setEnabled(enabled: Bool)
Parameters
enabled
TRUE
to enable,FALSE
to disable. -
Sets the minimum log level of the global logger - Parameter minLevel: The min log level to be used.
Declaration
Swift
public class func setMinLevel(minLevel: LogLevel)
Parameters
minLevel
The min log level to be used.
-
Sets the terminator of a log line in the console. Typically
\n
- Parameter terminator: Typically\n
.Declaration
Swift
public class func setTerminator(terminator: String)
Parameters
terminator
Typically
\n
. -
Sets the separator of elements in the log message. Typically
,
- Parameter terminator: Typically\n
.Declaration
Swift
public class func setSeparator(separator: String)
Parameters
terminator
Typically
\n
. -
Registers the file of the caller to a specific minimum log level - Parameter level: the minimum log level to be associated with the file - Parameter filePath: Should not be overwritten. It’s used to determine the filename of the caller
Declaration
Swift
public class func registerFile(level: LogLevel, filePath: String = #file)
Parameters
level
the minimum log level to be associated with the file
filePath
. It’s used to determine the filename of the caller
-
Triggers a log with under the debug log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public class func debug(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the trace log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public class func trace(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the info log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public class func info(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the warn log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public class func warn(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the error log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public class func error(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.
-
Triggers a log with under the fatal log level
Other than
message
these parameters should not be overwritten as they provide insight as to which file, line, column and function led to the call. If they are, then the LogFormat may not return the correct values thus the log message’s format will not be expected. - Parameter message: A series of objects to be logged. - Parameter filePath: Determines the file path of the caller. - Parameter line: Determines the line in the source code of the caller. - Parameter column: Determines the column in the source code of the caller. - Parameter function: Determines the function that triggered the call.Declaration
Swift
public class func fatal(message: CVarArgType..., filePath: String = #file, line: Int = #line, column: Int = #column, function: String = #function)
Parameters
message
A series of objects to be logged.
filePath
Determines the file path of the caller.
line
Determines the line in the source code of the caller.
column
Determines the column in the source code of the caller.
function
Determines the function that triggered the call.