Skip to main content
Version: 4.0.0

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.

caution

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

caution

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 of silent, error, warn, info, verbose, debug or silly.
  • options (Object):
    • transport (String): The Winston transport in which the level has to be set. Can be one of console or store. If not provided, the level is set to all transports. In the root logger, changes in the store transport will be applied also to the globalStore transport.
    • propagate (Boolean): Propagates the level change to all children namespaces recursively or not. Default is true.
    • pinned (Boolean): When true, next level changes coming from propagations will be ignored and the transport/transports will keep the defined level. Default is false.
    • forcePropagation (Boolean): When true, the propagation will ignore pinned levels and will always override them.
caution

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.