The built-in capacity Logging
provides tools for printing messages in the log associated to the agent.
For printing an error or a warning message, the two following functions are provided:
def error(message : Object, exception : Throwable = null, arguments : Object*)
def warning(message : Object, exception : Throwable = null, arguments : Object*)
The message
parameter is converted to a string for obtaining the message to output.
The message is built from the parsing of the message in which parameter constants aree replaced by the arguments
.
The exception
parameter may be given for printing an exception that is the cause of the logging action.
Examples:
agent A {
uses Logging
def myaction {
error("mymessage")
error("mymessage", new Exception)
warning("mymessage")
warning("mymessage", new Exception)
}
}
You could also give a text supplier, in the form of a lambda expression, to these logging functions in order to build the loggeable message dynamically.
agent A {
uses Logging
def myaction {
error [ "mymessage" ]
warning [ "mymessage" ]
}
}
For printing an information message, the following function is provided:
def info(message : Object, arguments : Object*)
The message
parameter is converted to a string for obtaining the message to output.
The message is built from the parsing of the message in which parameter constants aree replaced by the arguments
.
Example:
agent A {
uses Logging
def myaction {
info("mymessage")
}
}
You could also give a text supplier, in the form of a lambda expression, to the logging function in order to build the loggeable message dynamically.
agent A {
uses Logging
def myaction {
info [ "mymessage" ]
}
}
For printing a debugging message, the following function is provided:
def debug(message : Object, arguments : Object*)
The message
parameter is converted to a string for obtaining the message to output.
The message is built from the parsing of the message in which parameter constants aree replaced by the arguments
.
Example:
agent A {
uses Logging
def myaction {
debug("mymessage")
}
}
You could also give a text supplier, in the form of a lambda expression, to the logging function in order to build the loggeable message dynamically.
agent A {
uses Logging
def myaction {
debug [ "mymessage" ]
}
}
The printable messages are associated to a level of logging (error, warning, info, debug). If a message is given to the logging system, and the current output level is lower than the message’s level, then the message is not output.
For retrieving the current logging level, the following function is provided:
def getLogLevel : int
The replied value is 0 when no message is printed, 1 if only error messages are printed, 2 for error and warning messages, etc.
For changing the current logging level, the following function is provided:
def setLogLevel(level : int)
Example:
agent A {
uses Logging
def myaction {
var l = getLogLevel
setLogLevel( l + 1 )
}
}
The following functions permits testing if a specific logging level is enabled:
def isErrorLogEnabled : boolean
def isWarningLogEnabled : boolean
def isInfoLogEnabled : boolean
def isDebugLogEnabled : boolean
Example:
agent A {
uses Logging
def myaction : boolean {
isErrorLogEnabled
|| isWarningLogEnabled
|| isInfoLogEnabled
|| isDebugLogEnabled
}
}
By default, the logging message contains the identifier of the agent associated to the Logging
capacity.
Sometimes, it is helpful to change the printed name of the agent. The following function gives the opportunity to change this name.
def setLoggingName(name : String)
Example:
agent A {
uses Logging
def myaction {
setLoggingName("the name of the agent")
}
}
The Logging
capacity is based on the logging system of run-time virtual machine.
The getLogger
function provides you the access to the backend logger that is associated to the agent.
def getLogger : Logger
Copyright © 2014-2024 SARL.io, the Original Authors and Main Authors.
Documentation text and medias are licensed under the Creative Common CC-BY-SA-4.0; you may not use this file except in compliance with CC-BY-SA-4.0. You may obtain a copy of CC-BY-4.0.
Examples of SARL code are licensed under the Apache License, Version 2.0; you may not use this file except in compliance with the Apache License. You may obtain a copy of the Apache License.
You are free to reproduce the content of this page on copyleft websites such as Wikipedia.
Generated with the translator docs.generator 0.14.0.