Logging

Learn about logging features that help you debug your Jovo apps.

Introduction

The main logging feature provided by Jovo is Basic Logging, which logs the request and response of each interaction. This is especially relevant for debugging and support requests, for example in the Jovo Community Forum.

Most Jovo templates enable logging by default. You can find the configuration for this in the app.ts app configuration file:

const app = new App({
  logging: true,
  // ...
});

This default configuration will show the full request and response JSON objects in your logs. If you're developing locally, the logs are displayed in your terminal/command line. For other deployment environments, they show up in the respective log service, for example CloudWatch on AWS.

Jovo also offers an internal Logger that can be used for different log levels. Learn more in the Jovo Logger section.

Configuration

You can modify the logging configuration by turning logging: true into an object, like this:

new App({
  logging: {
    enabled: true,
    // ...
  },
  // ...
});

Here are all configurations:

logging: {
  enabled: true,
  request: { /* ... */ },
  response: { /* ... */ },
  maskValue: '[ Hidden ]',
  indentation: '  ',
  styling: true,
  colorizeSettings: { /* ... */ },
  tslog: { /* ... */ },
},
  • enabled: Enable Basic Logging for both requests and responses.
  • request: Configurations for request logging.
  • response: Configurations for response logging.
  • More information about indentation, style, and colorizeSettings can be found in the styling section.
  • tslog: Configurations for the logging library used by the Jovo Logger.

Basic Logging

Request Logging

You can specifically enable and disable the logging of requests with the following config:

logging: {
  request: true,
  // ...
},

For some platforms, the logs of a request can get quite long if you only need certain information. There are additional config properties to help you with this:

logging: {
  request: {
    enabled: true,
    objects: [],
    maskedObjects: [],
    excludedObjects: [],
  },
  // ...
},

objects can be used to only display the properties that are referenced as strings in the array. This can include nested objects. Here is an example:

logging: {
  request: {
    objects: [
    'request',
    'context.System.user'
    ],
  },
  // ...
},

In a similar fashion, you can also mask objects or completely remove them from the logs using excludedObjects.

Response Logging

You can specifically enable and disable the logging of responses with the following config:

logging: {
  response: true,
  // ...
},

Similar to request logging, you can use additional configurations to modify which elements should be displayed:

logging: {
  response: {
    enabled: true,
    objects: [],
    maskedObjects: [],
    excludedObjects: [],
  },
  // ...
},

Masking

As described in the request and response logging sections, you can add masking for specific request or response objects. This is helpful for sensitive data like access tokens or private user information that shouldn't be logged on a server or logging service like AWS Cloudwatch.

logging: {
  maskValue: '[ Hidden ]',
  request: {
    maskedObjects: [],
    // ...
  },
  response: {
    maskedObjects: [],
    // ...
  },
},

Instead of showing the object's content, the logs will display the maskValue, the default being [ Hidden ].

Styling

You can make changes to the log's styling with the following properties:

logging: {
  indentation: '   ',
  styling: true, // Enable or disable styling
  colorizeSettings: {
    colors: { // Change the display of colors
      STRING_KEY: 'white',
      STRING_LITERAL: 'green',
      NUMBER_LITERAL: 'yellow',
      BRACE: 'white.bold',
    },
  },
  // ...
},

Jovo Logger

Jovo has an internal Logger that can be used to display certain levels of logs. It is an instance of tslog and can use any features that library provides.

You can add tslog configurations (learn more on their website) to the tslog property, for example:

logging: {
  tslog: {
    prettyInspectOptions: { depth: 3 },
    prefix: [''],
    displayDateTime: false,
  },
  // ...
},

You can import the Jovo Logger like this:

import { Logger } from '@jovotech/framework';

You can use the logger to log to various log levels, which can be set as environment variable JOVO_LOG_LEVEL, for example like this:

process.env.JOVO_LOG_LEVEL = 'warn';

The logs can be done like this:

Logger.silly(string); // JOVO_LOG_LEVEL = 'silly'
Logger.trace(string); // JOVO_LOG_LEVEL = 'trace'
Logger.debug(string); // JOVO_LOG_LEVEL = 'debug'
Logger.info(string); // JOVO_LOG_LEVEL = 'info'
Logger.warn(string); // JOVO_LOG_LEVEL = 'warn'
Logger.error(new Error()); // JOVO_LOG_LEVEL = 'error'
Logger.fatal(new Error()); // JOVO_LOG_LEVEL = 'fatal'

Learn more about log levels in the official tslog documentation.