Logging
Logging
Scout logs internal activity via a configured logging function with the signature (msg: string, level: LogLevel) => void
.
Express middleware logging
To enable agent logging with the express
middleware, your middleware should be set up like the following:
const scout = require("@scout_apm/scout-apm");
const express = require("express");
// The "main" function of your application
async function start() {
// Create your express application
const app = express();
// Install scout
await scout.install(
// Configuration for the scout agent
{
allowShutdown: true, // allow shutting down spawned scout-agent processes from this program
monitor: true, // enable monitoring
name: "<application name>",
key: "<scout key>",
},
// Additional scout options
{
logFn: scout.consoleLogFn,
}
);
// Enable the app-wide scout middleware
app.use(scout.expressMiddleware());
// ... Add other middleware/handlers ...
app.listen(...);
}
If you are using winston
you may build a logFn
by passing a winston.Logger
to the exported scout.buildWinstonLogger
helper function:
logFn: scout.buildWinstonLogger(yourLogger),
If a winston.Logger
instance is provided, Scout’s logging defaults to the same log level as the instance, otherwise it defaults to ERROR
. You may set the logging to a stricter level to quiet the agent’s logging via the logLevel
in the config
sub-object (or SCOUT_LOG_LEVEL
via ENV). The underlying LoggerInterface’s level will take precedence if it is tighter than the logLevel
configuration.
Log Levels
The possible log levels are as follows:
DEBUG
INFO
WARN
ERROR