Configure Logging
You do not need to create a log source to send logs from the AppSignal for Node.js integration. An āapplicationā log source will be created automatically.Stand-alone usage
To use the logger, you need to import AppSignal and set up the logger using the.logger() function.
The .logger() function accepts two arguments: group and optionally severityThreshold. If severityThreshold is not provided, it will default to info.
trace, debug, info, log, warn, and error, each of them with its own function with the same name. These functions accept two arguments message and attributes. Attributes is used for metadata and is optional.
Messages will only be logged if their severity level is above the severity threshold.
Using multiple logging backends
Itās currently not possible to send logs to multiple backends using Node.jsā standard logger. For more complex setups, we recommend using a logging library like Winston or Pino.Usage with Winston
If you use Winston to log messages throughout your application, you can use our Winston transport to send those logs to AppSignal. After importing the transport from the AppSignal integration, add it to the list of transports in your Winston logger:Child Logger
You can use a child logger to add additional tags to log messages. You define tags when creating the child logger constant or pass tags as metadata when writing a log message. Say we want greater context in our logs of the actions of a particular user within a specific session. In the below example, a child logger for thebackground group is used to add sessionID with the additional drinkID, and paymentID tags are provided as metadata when creating a log message, and if a group is given to the child, itāll override the one set up in the transport.
Using multiple logging backends
To send logs to both AppSignalās logger andSTDOUT, add another transport:
Usage with Pino
If Pino is your preferred logging library, you can use the AppSignal Pino transport to send logs to AppSignal. The group argument will default to āappā if not provided.Using multiple logging backends
To send logs to both AppSignalās logger andSTDOUT, add another target:
Formats
Auto detected format
The AppSignal for Node.js package will automatically detect the log lineās format as JSON, Logfmt or plaintext by default, and parse attributes from it. You donāt need to manually set the log format, unless itās not being detected properly. Please also notify us if this isnāt working automatically.Logfmt
The AppSignal Logger can be explicitly configured to expect the line to be formatted as Logfmt and parse attributes from it. Use this option when using an older AppSignal for Node.js package version, which does not support automatic format detection. The log format can be specified when creating a logger. When initializing the AppSignal logger pass the"logfmt" value as the third argument.
JSON
The AppSignal Logger can be explicitly configured to expect the line to be formatted as JSON and parse attributes from it. Use this option when using an older AppSignal for Node.js package version, which does not support automatic format detection. The log format can be specified when creating a logger. When initializing the AppSignal logger pass the"json" value as the third argument.
Filtering Logs
You can use theignoreLogs configuration option to ignore log lines based on their message. See our Ignore Logs guide to learn more.