Skip to content

Logs

The Exot Inspector offers an invaluable logging instrument that provides developers with comprehensive insights into their application’s behavior. Logs play a crucial role in understanding and debugging software, allowing developers to track the flow of execution, identify errors, and analyze system performance.

Instrument

Access the logs instrument via the logs namespace:

inspector.instruments.logs

Configuration

Configure the logs instrument using the main Inspector configuration options:

const inspector = new Inspector({
instruments: {
logs: {
console: true,
stdout: true,
disabled: false,
},
},
});

Available configuration options:

  • console: boolean: Determines whether to capture console.* logs (default true).
  • stdout: boolean: Determines whether to capture process.stdout (default true).
  • disabled: boolean: Disables the instrument. When disabled, the instrument cannot be activated, and no data will be recorded (default false).

Capturing logs

The logs instrument seamlessly intercepts console.* functions and process.stdout, ensuring all log messages generated via console.* or written to stdout are automatically captured.

Pino logger

To leverage the logging instrument with Pino, configure Pino’s destination to process.stdout.

import pino from 'pino';
const logger = pino(process.stdout);

Custom logger

For alternative logging mechanisms, manually write to the Inspector’s logs using the push() function.

type push = (text: string, level: string, time?: number) => void;

The level parameter indicates the severity level of the log. It is recommended to use standard levels: trace, debug, info, warn, error, fatal.

inspector.instruments.logs.push('log text...', 'info');

Querying logs

While recorded logs can be viewed in the Application, you can programmatically retrieve logs using the query() function.

inspector.instruments.logs.query({
endTime: Date.now(),
startTime: Date.now() - 60000,
});