https://github.com/kth/kth-node-log
Logging module for Node.js applications.
https://github.com/kth/kth-node-log
Last synced: about 1 year ago
JSON representation
Logging module for Node.js applications.
- Host: GitHub
- URL: https://github.com/kth/kth-node-log
- Owner: KTH
- License: mit
- Created: 2016-08-31T14:46:37.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2025-04-01T04:49:01.000Z (about 1 year ago)
- Last Synced: 2025-05-22T07:48:45.210Z (about 1 year ago)
- Language: JavaScript
- Size: 564 KB
- Stars: 0
- Watchers: 20
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @kth/log
Logging module for Node.js applications.
## Usage
The package will respect NODE_ENV and output serialized JSON in production
and use ordinary output for development.
The package uses bunyan.stdSerializers.err for err and provides serializers for req and res objects. Only subset of fields are displayed by these serializers.
### In your application
```javascript
const log = require('@kth/log')
// in application setup, see full options below
log.init({
name: 'node-app',
level: 'warn',
})
// log usage
log.info('hello from info, log level usually used in setup')
log.warn('error that code handled and can recover from')
log.error({ err: err }, 'error that should be fixed in code')
log.fatal('a really bad error that will crash the application')
log.debug({ req: req, res: res }, 'log a request and response, basic dev log')
log.trace('granular logging, rarely used')
// child logger
// add custom values to all of the logs
const myLog = log.child({ custom: 'value' })
myLog.info('hello')
```
## Options
```javascript
log.init({
// name of the logger, usually the same as application name, default is 'node-log'
name: 'node-app',
// If developement or test, the output is sent to stdout (console) using Bunyan-format 'short', default value is retrieved from process.env.NODE_ENV
env: 'development',
// default logging level is INFO
level: 'debug',
// Provide a custom serializer if necessary, default serializer for err, req and res are included in the package.
serializers: {
err: customSerializer,
},
})
```