1.1.26 • Published 4 months ago
@hiryus-org/tracer v1.1.26
Installation
npm install @hiryus-org/tracer
Usage
// Import library
const tracer = require('@hiryus-org/tracer');
// By default, event message is output as text on the console for all default
// levels (fatal, error, warning, info, debug, trace and access).
// See "configuration" section to change it.
// The log event, you can use the log() function:
// tracer.log(level, message, [metadata])
tracer.log('info', 'application started');
tracer.log('access', 'GET /article/157', { ip: '127.0.0.1' });
// There are also shortcuts for the default log levels.
// Metadata is facultative too.
tracer.fatal('message', { foo: 'bar' });
tracer.error('message', { foo: 'bar' });
tracer.warn('message', { foo: 'bar' });
tracer.info('message', { foo: 'bar' });
tracer.debug('message', { foo: 'bar' });
tracer.trace('message', { foo: 'bar' });
tracer.access('message', { foo: 'bar' });
Configuration
const tracer = require('@hiryus-org/tracer');
tracer.loggers.clear(); // to remove defautl loggers
tracer.loggers.add({
levels: ['fatal', 'error'],
type: 'console',
format: 'text',
});
tracer.loggers.add({
levels: ['fatal', 'error', 'warning', 'info', 'debug', 'trace'],
type: 'file',
format: 'json.raw',
path: 'application.log',
});
// or in one go:
tracer.loggers.set([{
levels: ['fatal', 'error'],
type: 'console',
format: 'text',
}, {
levels: ['fatal', 'error', 'warning', 'info', 'debug', 'trace'],
type: 'file',
format: 'json.raw',
path: 'application.log',
}]);
Formats
text
: outputs each event message as a text line (metadata is ingored for this format)json.raw
: outputs each event as a JSON string, one event per line (and thus, without indentation)json.pretty
: outputs each event as a JSON string with indentation and line breaks
Test
- To launch tests, just run
npm run test
. - To gather coverage data, run
npm run coverage
. Coverage reports are in thecoverage
directory.
Contribute
1.1.26
4 months ago
1.1.25
3 years ago
1.1.24
3 years ago
1.1.23
3 years ago
1.1.22
3 years ago
1.1.21
3 years ago
1.1.20
3 years ago
1.1.19
3 years ago
1.1.18
3 years ago
1.1.17
3 years ago
1.1.16
3 years ago
1.1.15
3 years ago
1.1.14
3 years ago
1.1.13
3 years ago
1.1.12
3 years ago
1.1.9
3 years ago
1.1.11
3 years ago
1.1.10
3 years ago
1.1.8
3 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago