npm: npmjs.com/package/@digipolis/log
Log helper which converts default logs to indexable json log.
https://github.com/digipolisantwerpdocumentation/logging-requirements
$ npm i @digipolis/log
$ yarn add @digipolis/log
Param | Description | Values |
---|---|---|
type (optional) | Set logging mode | log (default) / json / text / silent |
override (optional) | Set to override given console (default) | true / false (default) |
const digipolisLogger = require('@digipolis/log');
const mylogger = digipolisLogger(console, {
type: 'text', // log(default) | json | text
override: false, // false(default) | true
});
// human readable for local development
mylogger.log('hello');
/*
type: 'text' -> INFO: 2021-12-01T09:43:19.173Z hello
*/
const mylogger = digipolisLogger(console, {
type: 'json', // log(default) | json | text
override: false, // false(default) | true
});
// human readable json local development
mylogger.log('hello');
/*
type: 'json' -> {
message: 'hello',
timestamp: '2021-12-01T09:44:20.565Z',
type: [ 'technical' ],
level: 'INFO',
correlationId: ''
}
*/
const mylogger = digipolisLogger(console, {
type: 'log', // log(default) | json | text
override: false, // false(default) | true
});
// log for kibana json for production
mylogger.log('hello');
/*
type: 'log' -> {"message":"hello","timestamp":"2021-12-01T09:45:56.515Z","type":["technical"],"level":"INFO","correlationId":""}
*/
const digipolisLogger = require('@digipolis/log');
digipolisLogger((console, {
type: 'text', // log(default) | json | text
override: true, // false(default) | true
});
// human readable for local development
console.log('hello');
/*
type: 'text' -> INFO: 2021-12-01T09:43:19.173Z hello
*/
digipolisLogger((console, {
type: 'json', // log(default) | json | text
override: true, // false(default) | true
});
// human readable json local development
console.log('hello');
/*
type: 'json' -> {
message: 'hello',
timestamp: '2021-12-01T09:44:20.565Z',
type: [ 'technical' ],
level: 'INFO',
correlationId: ''
}
*/
digipolisLogger((console, {
type: 'log', // log(default) | json | text
override: true, // false(default) | true
});
// log for kibana json for production
console.log('hello');
/*
type: 'log' -> {"message":"hello","timestamp":"2021-12-01T09:45:56.515Z","type":["technical"],"level":"INFO","correlationId":""}
*/
// type: json
console.log('hello');
/*
{
message: 'hello',
timestamp: '2021-12-01T09:44:20.565Z',
type: [ 'technical' ],
level: 'INFO',
correlationId: ''
}
*/
// type: json
console.error('hello');
/*
{
message: 'hello',
timestamp: '2021-12-01T09:44:20.565Z',
type: [ 'technical' ],
level: 'ERROR',
correlationId: ''
}
// type: json
*/
console.error(new Error('Errormessage'));
/*
{
message: 'Errormessage Error: Errormessage\n' +
' at Object.<anonymous> (/Users/oliviervandenmooter/Projects/Digipolis/diglog/example/index.js:17:13)\n' +
' at Module._compile (node:internal/modules/cjs/loader:1095:14)\n' +
' at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)\n' +
' at Module.load (node:internal/modules/cjs/loader:975:32)\n' +
' at Function.Module._load (node:internal/modules/cjs/loader:816:12)\n' +
' at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)\n' +
' at node:internal/main/run_main_module:17:47',
timestamp: '2021-12-01T11:00:13.073Z',
type: [ 'technical' ],
level: 'ERROR',
correlationId: ''
}
*/
// structured message
console.log({ message: 'logmessage2', timestamp: 'timestamp123' })
/*
{
message: 'logmessage2',
timestamp: 'timestamp123',
type: [ 'technical' ],
level: 'INFO',
correlationId: ''
}
// structured message with extra params
*/
console.log({ message: 'logmessage2', timestamp: 'timestamp123', extra_param1: "extra_value" });
/*
{
message: 'logmessage2 Extrainfo: {"extra_param1":"extra_value"}',
timestamp: 'timestamp123',
type: [ 'technical' ],
level: 'INFO',
correlationId: ''
}
*/
Run the tests in this repo:
$ npm run test
$ npm run coverage
none.
We use SemVer
for versioning. For the released version check changelog / tags
Pull requests are always welcome, however keep the following things in mind:
- New features (both breaking and non-breaking) should always be discussed with the repo's owner. If possible, please open an issue first to discuss what you would like to change.
- Fork this repo and issue your fix or new feature via a pull request.
- Please make sure to update tests as appropriate. Also check possible linting errors and update the CHANGELOG if applicable.
- Olivier Van den Mooter (olivier.vandenmooter@digipolis.be) - Initial work - Vademo
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details