core.logger
Preface
The core.logger
object provides methods for printing and storing logs. It allows to create namespaces, so each namespaced logger provides information about its label. Each namespace log level can be set separately and each one contains also a separated logs store.
Use only the API methods described in this docs. Use other methods under your own risk, and take into account that they may change in minor versions without considering it as a breaking change.
API
When the core is passed to a plugin as a parameter, the logger
object is a logger
namespace instead of the root logger
instance. The logger
namespace is labeled with the plugin id, so it is easy to trace where the logs come from.
error()
core.logger.error(message)
: Log a message with error
level. The message will be logged always except if the current level
is silent
.
warn()
core.logger.warn(message)
: Log a message with warn
level. The message will be logged always except if the current level
is error
or silent
.
info()
core.logger.info(message
: Log a message with info
level. The message will be logged whenever the current level
is not error
, warn
or silent
.
verbose()
core.logger.verbose(message)
: Log a message with verbose
level. The message will be logged whenever the current level
is upper or equal than verbose
.
debug()
core.logger.debug(message)
: Log a message with debug
level. The message will be logged whenever the current level
is upper or equal than debug
.
silly()
core.logger.silly(message)
: Log a message with silly
level. The message will be logged whenever the current level
is upper or equal than silly
.
setLevel()
core.logger.setLevel(level, [options])
: Set the logger current log level for the current namespace and all children namespaces recursively.
level
(String): Level can be one ofsilent
,error
,warn
,info
,verbose
,debug
orsilly
.options
(Object):transport
(String): TheWinston
transport in which the level has to be set. Can be one ofconsole
orstore
. If not provided, the level is set to all transports. In the root logger, changes in thestore
transport will be applied also to theglobalStore
transport.propagate
(Boolean): Propagates the level change to all children namespaces recursively or not. Default istrue
.pinned
(Boolean): Whentrue
, next level changes coming from propagations will be ignored and the transport/transports will keep the definedlevel
. Default isfalse
.forcePropagation
(Boolean): Whentrue
, the propagation will ignorepinned
levels and will always override them.
This method should not be used directly until you know well what you are doing. Use the config API to set the global log level instead (core.config.option("log").value="x"
).
namespace()
core.logger.namespace(label)
: Create and return a new child namespace or returns an already existent one when the label
already exists. The returned namespace has the same Logger
methods described here. The created namespace will inherit the current namespace level.
label
(String): Label for the new namespace. It will be displayed as part of the log[label]
, appended to parent namespaces labels.
cleanStore()
core.logger.cleanStore()
Empties the namespace store array.
onChangeStore()
core.logger.onChangeStore(callback)
: Allows to add a listener that will be executed whenever a log is added to the current namespace store. It returns a function that removes the listener once executed.
callback()
(Function): Callback to be executed.
onChangeGlobalStore()
core.logger.onChangeGlobalStore(callback)
: Allows to add a listener that will be executed whenever a log is added to the global store. It returns a function that removes the listener once executed.
callback()
(Function): Callback to be executed.
store
core.logger.store
: Returns an array with logs stored in the current namespace.
globalStore
core.logger.globalStore
: Returns an array with logs stored in all namespaces, including those from the ancestors. There is only one global namespace for each Logger
instance, no matter the amount of namespaces it has.
label
core.logger.label
: Getter returning the namespace label.
level
core.logger.level
: Getter returning the current namespace level.
root
core.logger.root
: Getter returning the root logger instance.