Documentationcurrent version
Help us improve the docs by fixing typos and proposing enhancements.

Nikita

Tool "log"

The log tool is a function to publish information about the state of Nikita's actions.

It is possible to listen to the emitted log objects and to use their information for logging or debugging. The log.cli action prints the status of the Nikita session to the console. The log.md action dumps the logs into a file using the Markdown format.

Emitted log objects are also available in the $logs array returned in the action output.

The log function relies internally on the Node.js events module and it uses the tools.events.emit function.

Usage

It is available inside the action handler as the tools.log property of the first argument.

To emit an event, call the tools.log function passing properties to the argument object:

nikita
// Call an action
.call(({tools}) => {
// Emit an event
tools.log({
  level: 'DEBUG',
  message: 'Some message'
})
})

To pass only the message property, call it with a string argument:

nikita
// Call an action
.call(({tools}) => {
// Emit an event
tools.log('Some message')
})

Log object

The log object contains the information about the state of an action and consist of the following properties:

  • depth
    The depth level of the action in the Nikita session tree. See the depth metadata for complementary information.
  • index
    The index position of the action relative to its siblings. See the index metadata for complementary information.
  • filename
    The full path to the file where the event is emitted.
  • file
    The filename where the event is emitted.
  • level
    The log level, default is INFO. Suggested values are DEBUG, INFO, WARN, ERROR.
  • line
    The line number where the event is emitted.
  • message
    The user message.
  • module
    The path to the Node.js module of the registered action honored from the module metadata.
  • namespace
    The list of names of the action from root to a child. It is honored from the module metadata.
  • position
    The list of indices corresponding to the position in the hierarchical tree of the Nikita session. See the position metadata for complementary information.
  • time
    The Unix timestamp of the date when the event is emitted.
  • type
    The Node.js event name, default to text. See the events tool for a list of supported event types.
Edit on GitHub
Navigate
About

Nikita is an open source project hosted on GitHub and developed by Adaltas.