Package Exports
- @neo9/n9-node-log
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@neo9/n9-node-log) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
n9-node-log
Logging node module based on Winston.
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.verbose('This is a verbose 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
at Object.<anonymous> (/home/schopin/Neo9/node-ts-skeleton/src/index.ts:16:28)
at Module._compile (module.js:571:32)
at ...
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
environement.
Possible values:
verbose
: Display all logsdebug
: Display debug + info + warn + error logsinfo
: Display info + warn + error logswarn
: Display info + warn logserror
: Display only error logs
Default value: verbose
Example: N9LOG=error node server.js
will display only error logs.
Transports
Define the transporter(s) you want to use to store your logs, notice that you can combine them.
console
Will output the logs into process.stdout
and process.stderr
.
- Type:
Boolean
- Default:
true
Example:
const log = n9Log('my-app-name', {
console: false, // Don't output the logs into the console
})
files
Will write the log output into specified file(s).
- Type:
Array
- Default:
[]
- Properties:
level
: Level of messages to write into the file (default:'info'
)filename
: Path of the logfilemaxsize
: Max sizes in bytes of the logfilemaxFiles
: Limit the number of files created
Example:
const log = n9Log('my-app-name', {
files: [
{
level: 'info',
filename: '/tmp/info-log.log'
}
]
})
http
- Type:
Array
- Default:
[]
- Properties:
host
: (Default:'localhost'
) Remote host of the HTTP logging endpointport
: (Default:80
or443
) Remote port of the HTTP logging endpointpath
: (Default:'/'
) Remote URI of the HTTP logging endpointauth
: (Default: None) An object representing theusername
andpassword
for HTTP Basic Authssl
: (Default:false
) Value indicating if we should us HTTPS
Example:
const log = n9Log('my-app-name', {
http: [
{
host: 'my-logs.io',
path: '/save',
ssl: true
}
]
})