Sailor logger
Description
Information about currently used logger in components and how to implement it in your components. This document describes the changes in node.js sailor from January 2020.
In 2020, a new executions page was introduced to the platform.
Unlike the main dashboard which shows log statements from both console.log()
and this.logger.info()
, the new executions page will show the logs if you envelop your message in this.logger.info()
.
To take advantage of this new executions page your component must use this.logger.info() to envelope the messages or in technical terms, your must switch to the Bunyan logging framework and upgrade the Sailor version to at least 2.5.4.
About the built-in logger
Every process()
function will have a property logger attached to the context of the function that can be accessed by referencing this.
The logger object is an instance of a Bunyan Logger. It exposes 6 levels of log statements (from highest to lowest):
- this.logger.fatal
-
The service/app is going to stop or become unusable now. An operator should immediately look into this.
- this.logger.error
-
This is fatal for a particular request, but the service/app continues servicing other requests. An operator should look at this as a matter of urgency.
- this.logger.warn
-
This is a note on something that should probably be looked at by an operator eventually.
- this.logger.info
-
This is a detail of a regular operation.
- this.logger.debug
-
This is too verbose to be included in the info level.
- this.logger.trace
-
This is logging from external libraries used by your app or very detailed application logging.
Only statements of info or higher level will appear on the executions page.
|
Most other exported functions (for example, verifyCredenitals()
, getMetaModel()
and functions which populate dynamic drop-downs) also have this logger attached.
However, the logger is not available in the init()
, shutdown()
or startup()
functions.
As of early 2020, it is no longer possible to record log statements from those functions.
How to use the built-in logger
In a component process()
function, change console.log
to this.logger
as shown in the two samples below:
module.exports.process = async function process(msg, cfg, snapshot) {
console.log('Incoming message is %s', JSON.stringify(msg)); (1)
const body = { result : 'Hello world!' };
await this.emit('data', { body });
console.log('Execution finished'); (1)
}
1 | Using console.log |
module.exports.process = async function process(msg, cfg, snapshot) {
this.logger.info('Incoming message is %s', JSON.stringify(msg)); (1)
const body = { result : 'Hello world!' };
await this.emit('data', { body });
this.logger.info('Execution finished'); (1)
}
1 | Using this.logger |
If you call into a child function from within your parent process function, you will need to pass the logger as an argument to the child function.
async function buildMessage(resultText) {
console.log(resultText);
return { body: { result : 'Hello world!' }};
}
module.exports.process = async function process(msg, cfg, snapshot) {
const message = buildMessage('Hello world!');
await this.emit('data', { body });
}
async function buildMessage(logger, resultText) { (1)
logger.info(resultText); (1)
return { body: { result : 'Hello world!' }};
}
module.exports.process = async function process(msg, cfg, snapshot) {
const message = buildMessage(this.logger, 'Hello world!'); (1)
await this.emit('data', { body });
}
1 | Using this.logger . |
async function buildMessage(resultText) {
this.logger.info(resultText); (1)
return { body: { result : 'Hello world!' }};
}
module.exports.process = async function process(msg, cfg, snapshot) {
const message = buildMessage.call(this, 'Hello world!'); (2)
await this.emit('data', { body }); (3)
}
1 | Alternate method to use this.logger . |