Logging and analysis

Published at: April 27, 2018, 8:43 a.m. in the Documentation

Logging

In your API you can use logging, you need to import the logger object and call one of the levels:

const { logger } = require('smappi-cl');
try {
     // your code here
} catch (err) {
     logger.error(err);
}
logger.info('Test of logger') // or logger.log as alias
logger.warn('My first warn')

If your code already uses console, but you want to replace it with logging, then it is enough to assign it as an alias:

const { logger: console } = require('smappi-cl');
console.log('Test of console')
console.warn('My second warn')

Levels

For production available:

  • ERROR (logger.error)
  • WARNING (logger.warn, logger.warning)
  • INFO (logger.info, logger.log)

For local development (Console):

  • ERROR (console.error)
  • WARNING (console.warn, console.warning)
  • INFO (console.info, console.log)
  • DEBUG (console.debug)

Analysis

When the use of logger you will locally see errors in the console of your terminal.
The API running in production will log into ElasticSearch and display the log in the Log tab that every project has.

In the Log tab, you can filter by levels and search by message body.