Logger
public class Logger
Logs events of interest.
A LogRecord describes a loggable event. Each record has a level which reflects the importance
of the event. If the log level of a record is at least as high as the level of the logger,
the logger dispatches the record to the logger’s current handler.
Example:
let logger = Logger()
logger.level = .warning
logger.handler = ConsoleLogHandler()
let record = LogRecord(level: .warning,
message: "Watch out!",
context: "Session-14",
timestamp: Date(),
file: #file,
function: #function,
line: #line)
logger.log(record) // the record is logged (because LogLevel.warning >= logger.level)
// Convenience methods make logging more concise.
logger.warning("Watch out!", context: "Session-14")
// Examples of other log levels:
logger.severe("This is also logged") // because LogLevel.severe >= logger.level
logger.info("This is not logged") // because LogLevel.info < logger.level
Logger is threadsafe.
See also
Postgres.logger
-
Creates a
Logger.Declaration
Swift
public init() -
The log level for this logger. Defaults to
LogLevel.info.Declaration
Swift
public var level: LogLevel { get set } -
The log handler for this logger. Defaults to a
ConsoleLogHandler.Declaration
Swift
public var handler: LogHandler { get set } -
Processes the specified log record.
Declaration
Swift
public func log(_ record: LogRecord)Parameters
recordthe log record
-
Convenience method to log an event.
Declaration
Swift
public func log(level: LogLevel, message: CustomStringConvertible, context: CustomStringConvertible? = nil, file: String = #file, function: String = #function, line: Int = #line)Parameters
levelthe log level that reflects the importance of the event
messagea message describing the event
contextthe context of the event, such as a session or connection identifier
filethe name of the file that logged the event
functionthe name of the function that logged the event
linethe line number that logged the event
-
Equivalent to
log(level: .severe, ...).Declaration
Swift
public func severe(_ message: String, context: CustomStringConvertible? = nil, file: String = #file, function: String = #function, line: Int = #line) -
Equivalent to
log(level: .warning, ...).Declaration
Swift
public func warning(_ message: String, context: CustomStringConvertible? = nil, file: String = #file, function: String = #function, line: Int = #line) -
Equivalent to
log(level: .info, ...).Declaration
Swift
public func info(_ message: String, context: CustomStringConvertible? = nil, file: String = #file, function: String = #function, line: Int = #line) -
Equivalent to
log(level: .fine, ...).Declaration
Swift
public func fine(_ message: String, context: CustomStringConvertible? = nil, file: String = #file, function: String = #function, line: Int = #line) -
Equivalent to
log(level: .finer, ...).Declaration
Swift
public func finer(_ message: String, context: CustomStringConvertible? = nil, file: String = #file, function: String = #function, line: Int = #line) -
Equivalent to
log(level: .finest, ...).Declaration
Swift
public func finest(_ message: String, context: CustomStringConvertible? = nil, file: String = #file, function: String = #function, line: Int = #line)