-
Notifications
You must be signed in to change notification settings - Fork 0
utils.logging.wren
Inspired on Swift Log https://github.com/apple/swift-log
Its central function is to emit log messages using one of the methods corresponding to a log level.
The most basic usage of a Logger
is
- Example:
import "domepunk/utils/logging" for Logger
var label = "domepunk.test.logger"
var logger = Logger.new(label)
logger.info("Hello World!")
- Since:
1.0.0
Get or set the configured log handler.
Defaults to SystemPrintLogHandler
Get or set the configured log label.
An identifier of the creator of this Logger
.
Defaults to System.Logger
.
Get or set the configured log level.
Creates a new Logger with specified label and handler.
- Signature:
construct new(label:String?, handler:LogHandler?) -> Logger
Log a message passing with the level
log level.
If level
is at least as severe as the Logger
's log level
, it will be logged,
otherwise nothing will happen.
- Signature:
trace(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
Log a message passing with the LogLevel.trace
log level.
If .trace
is at least as severe as the Logger
's logLevel
, it will be logged,
otherwise nothing will happen.
- Signature:
trace(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
Log a message passing with the LogLevel.debug
log level.
If .debug
is at least as severe as the Logger
's logLevel
, it will be logged,
otherwise nothing will happen.
- Signature:
debug(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
Log a message passing with the LogLevel.info
log level.
If .info
is at least as severe as the Logger
's logLevel
, it will be logged,
otherwise nothing will happen.
- Signature:
info(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
Log a message passing with the LogLevel.notice
log level.
If .notice
is at least as severe as the Logger
's logLevel
, it will be logged,
otherwise nothing will happen.
- Signature:
notice(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
Log a message passing with the LogLevel.warning
log level.
If .warning
is at least as severe as the Logger
's logLevel
, it will be logged,
otherwise nothing will happen.
- Signature:
warning(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
Log a message passing with the LogLevel.error
log level.
If .error
is at least as severe as the Logger
's logLevel
, it will be logged,
otherwise nothing will happen.
- Signature:
error(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
Log a message passing with the LogLevel.critical
log level.
If .critical
is at least as severe as the Logger
's logLevel
, it will be logged,
otherwise nothing will happen.
- Signature:
critical(message:String, metadata:Map?, file:String?, function:String?, line:Num?) -> Void
- Parameters:
- message: The message to be logged.
message
can be used with any string interpolation literal. - metadata: optional One-off metadata to attach to this log message
- file: optional The file this log message originates from.
- function: optional The function this log message originates from.
- line: optional The line this log message originates from.
- message: The message to be logged.
The log level.
Log levels are ordered by their severity, with .trace
being the least severe and
.critical
being the most severe.
Disable all logging
Appropriate for messages that contain information only when debugging a program.
Appropriate for messages that contain information normally of use only when debugging a program.
- Alias:
log
Appropriate for informational messages.
Appropriate for conditions that are not error conditions, but that may require special handling.
Appropriate for messages that are not error conditions, but more severe than
.notice
.
Appropriate for error conditions.
Appropriate for critical error conditions that usually require immediate attention.
Level Name
- Signature:
name:String
Level Severity
- Signature:
severity:Num
A LogHandler
is an implementation of a logging backend.
Get or set the entire metadata storage as a map.
Get or set the configured log level.
Defaults to LogLevel.info
This method is called when a LogHandler
must emit a log message. There is no need for the LogHandler
to
check if the level
is above or below the configured logLevel
as Logger
already performed this check and
determined that a message should be logged.
- Signature:
log(level: LogLevel, message: Logger.Message, metadata: Logger.Metadata?, file: String?, function: String?, line: Num?)
- Parameters:
- level: The log level the message was logged at.
- message: The message to log. To obtain a
String
representation callmessage.description
. - metadata: The metadata associated to this log message.
- file: The file the log message was emitted from.
- function: The function the log line was emitted from.
- line: The line the log message was emitted from.
A Log Handler that use System.print()