5.0.0 • Published 1 year ago
@neo9/n9-node-log v5.0.0
n9-node-log
Logging node module based on Pino.
Requirements
- NodeJS >= 10.0.0
Installation
npm install --save @neo9/n9-node-log
Usage
import n9Log from '@neo9/n9-node-log';
const log = n9Log('my-app-name');
// Write on stdout
log.trace('This is a trace message');
log.debug('This is a debug message');
log.info('This is an information message');
log.warn('Warning, this feature will be removed soon');
// Write on stderr
log.error('An error appened');
2017-05-12T15:57:14.474Z - info: [my-app-name] This is an information message
2017-05-12T15:57:14.689Z - warn: [my-app-name] Warning, this feature will be removed soon
2017-05-12T15:57:14.974Z - error: [my-app-name] An error appened
Metadata
log.info('Log with metadata', { anything: 'this is metadata' });
log.error('Here an error', new Error('hello'));
2017-05-12T15:57:14.474Z - info: [my-app-name] Log with metadata anything=this is metadata
2017-05-12T15:57:14.785Z - error: [node-ts-skeleton] Here an error Error: hello
err: {
"type": "Error",
"message": "something-went-wrong",
"stack":
Error: something-went-wrong
at /home/bdaniel/projects/neo9/n9-libs/n9-node-log/test/index.ts:110:29
}
Prefixing
const logUsers = log.module('users');
logUsers.info('Log specific to users module');
2017-05-12T15:57:14.474Z - info: [my-app-name:users] Log specific to users module
Profiling
log.profile('test');
setTimeout(() => log.profile('test'), 1000);
2017-05-12T15:57:14.474Z - info: [my-app-name] test {"durationMs":1000}
Log level
You can filter the list of logs on startup with the N9LOG
environment or with the level
option.
Possible values:
trace
: Display all logsdebug
: Display debug + info + warn + error logsinfo
: Display info + warn + error logswarn
: Display warn + error logserror
: Display only error logs
Default value: info
Example: N9LOG=error node server.js
will display only error logs.
For performance matter, you can check if you need to compute your log data :
if (log.isLevelEnabled('debug')) {
log.debug('My debug log', { complexDataAsOneField: JSON.stringify(data) });
}
Breaking changes from V3 to V4
- Log level verbose renamed to log level trace
- JSON Format is enabled by default, it wasn't before
- Remove transports features
- Filters function change their signatures
5.0.0
1 year ago
5.0.0-rc.0
1 year ago
5.0.0-rc.1
1 year ago
5.0.0-rc.2
1 year ago
5.0.0-rc.3
1 year ago
5.0.0-rc.4
1 year ago
5.0.0-rc.5
1 year ago
5.0.0-rc.6
1 year ago
5.0.0-rc.7
1 year ago
4.1.0
2 years ago
4.0.1
3 years ago
3.2.1
3 years ago
4.0.0-rc.1
3 years ago
4.0.0-rc.0
3 years ago
4.0.0-rc.3
3 years ago
4.0.0-rc.2
3 years ago
4.0.0
3 years ago
3.2.0
4 years ago
3.1.1
4 years ago
3.1.0
4 years ago
3.0.0
4 years ago
3.0.0-rc.4
4 years ago
3.0.0-rc.3
4 years ago
3.0.0-rc.2
4 years ago
3.0.0-rc.1
5 years ago
3.0.1-0
5 years ago
3.0.0-rc.0
5 years ago
2.6.0
7 years ago
2.5.2
7 years ago
2.5.1
7 years ago
2.5.0
7 years ago
2.4.0
7 years ago
2.3.1
7 years ago
2.2.2
7 years ago