Anvil Connect uses bunyan for logging.
The default stdout
and file
streams can be enabled or disabled by editing your JSON configuration file. The default log level is INFO,
but it can be specified here too.
{
// ...
"logger": {
"stdout": true,
"file": true,
"level": "debug"
}
}
You can also create more sophisticated logging schemes with fine-grained log levels by creating a module called logger.js
in the same directory of your project as server.js
.
module.exports = {
name: 'anvilconnect',
streams: [
{
level: 'info',
stream: process.stdout // log INFO and above to stdout
},
{
level: 'error',
path: '/var/tmp/myapp-error.log' // log ERROR and above to a file
}
]
}
Note: if you are using Docker you will also need to update your Dockerfile to include COPY ./logger.js /opt/connect/logger.js
Log Level
level: fatal|error|warn|info|debug|trace
See Bunyan's log level options for more information on the meaning behind these configuration options.
Log Rotation
const logFilePath = path.join(cwd, 'logs', env + '.log')
module.exports = {
name: 'anvilconnect',
streams: [
{
level: 'info',
path: logFilePath,
type: 'rotating-file',
period: '1d', // rotation frequency
count: 10 // number of copies to retain
}
]
}
See Bunyan's log rotation documentation for more information.
Stdout
# Run Anvil locally and pretty-print all logs.
node server.js | node_modules/.bin/bunyan
# Run Anvil locally and show 'warn' logs or above.
node server.js | node_modules/.bin/bunyan -l warn
# Run Anvil locally and ONLY show debug logs.
node server.js | node_modules/.bin/bunyan -c 'this.level == 20'
Also see Bunyan CLI.