Skip to main content

Logging

When hosted on Unito's infrastructure, anything a connector sends to STDOUT will be logged. A connector created using the SDK comes with a logger that can help produce well formatted logs.

You can access the pre-configured logger through any handlers' context.

warning

This logger is decorated with information relative to the current call, so always use the logger of the current context.


export const getItem: GetItemHandler = async context => {
context.logger.info('working!);
};

This logger will already be decorated with the current call context to include all the relevant information as metadata.

This includes:

  • Correlation Id: The correlationId is a unique identifier received through the header X-Unito-Correlation-Id to helps us trace a request that goes through the different Unito services when monitoring or debugging an issue.
  • Additional Logging Context: Any Unito service can populate a header called X-Unito-Additional-Logging-Context to add context information it deems appropriate. This information is added to the logs to help monitoring and debugging.

You may want to have additional information added to every future log done through the current logger (valid for a given call). To do so, you can use the decorate method.

export const getItem: GetItemHandler = async context => {
context.logger.decorate({
itemId: context.params.id,
something: 'else'
});

context.logger.info('working!);
};

This log will generate the following output:

(info) {message: 'working!', correlationId: 'xxxxxxxxx', itemId: 'xyz', something: 'else', /*Any additional data configured*/}