
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
@noveo/logger
Advanced tools
Lightweight, customizable and flexible logger module. :rocket: :zap:
npm install @noveo/logger --save
const logger = require('@noveo/logger');
logger.configure({
transport: 'native',
level: 'debug',
useTimezone: true,
applicationId: 'app-name',
format: '{datetime} {pid} {ctx.requestId} [{level}] [{full-tag}] {message} {meta}',
dateFormat: 'DD.MM.YYYY HH:mm:ss.SSS'
});
const log = logger.getLogger('logger-name');
log.info('Some fun message', { meta: 'object' });
// => 16.06.2018 21:00:22.521 3457 0 [info] [app-name:logger-name] Some fun message { "meta": "object" }
Its object contains the executing environment, such as request ID, user data, request source object and other.
Configure logger. Can be executed once on start system. Config options have different fields for different transports.
const logger = require('@noveo/logger');
logger.configure({
transport: 'native',
level: 'debug',
useTimezone: true,
applicationId: 'app-name',
format: '{datetime} {pid} {ctx.requestId} [{level}] [{full-tag}] {message} {meta}',
dateFormat: 'DD.MM.YYYY HH:mm:ss.SSS'
})
Create logger instance by base config and with the custom name. Return instance of Logger class
Create message with default context and write him to output stream with level "LEVEL"
log.info('Info message');
// => 31.01.2017 16:44:55.599 3457 0 [INFO] [app-name::my-module-name] Info message
log.warn('Warning message', {
userName: 'Cool'
});
// => 31.01.2017 16:44:55.599 3457 0 [WARN] [app-name::my-module-name] Warning message {"userName": "Cool"}
Create message with context and write him to output stream with level "LEVEL"
log.info({requestId: 45}, 'Info message');
// => 31.01.2017 16:44:55.599 3457 45 [INFO] [app-name::my-module-name] Info message
log.warn({requestId: 48}, 'Warning message', {
userName: 'Cool'
});
// => 31.01.2017 16:44:55.599 3457 48 [WARN] [app-name::my-module-name] Warning message {"userName": "Cool"}
Create child logger instance with extra context and predifined tag.
const log = logger.getLogger('tag-name');
const childLog = log.child('child-tag');
log.info('I am child!');
// => 16.02.2017 09:59:27.821 3457 0 [info] [module-name:tag-name.child-tag] I am child!
const log = logger.getLogger('tag-name');
const childLog = log.child('child-tag', {
requestId: 75
});
log.info('I am child!');
// => 16.02.2017 09:59:27.821 3457 75 [info] [module-name:tag-name.child-tag] I am child!
Create Profile instance.
const log = logger.getLogger('tag-name');
const profile = log.startProfiling('mainController');
// => 16.02.2017 09:59:27.821 3457 0 [debug] [module-name:tag-name.profile] Profiling "mainController" start
log.info(`Current value of profile ${profile}ms`);
// => 16.02.2017 09:59:27.821 3457 0 [info] [module-name:tag-name.profile] Current value of profile 34ms
profile.stop();
// => 16.02.2017 09:59:39.821 3457 0 [debug] [module-name:tag-name.profile] Profiling "mainController" finished in 12045ms
// ... some time later
log.info(`Profile value don\`t increase - ${profile}ms`);
// => 16.02.2017 09:59:49.023 3457 0 [info] [module-name:tag-name.profile] Profile value don`t increase - 12045ms
API for render profiling messages by logger instance
Create new instance
ProfileGet current value of profile
StringConvert current value to string
ProfileStop time counting
Logging to STDOUT stream in one line format by template string. Settings:
const logger = require('@noveo/logger');
logger.configure({
transport: 'native',
format: '${datetime} ${ctx.requestId} [${level}] [${full-tag}] ${message} ${meta}'
})
const logger = require('@noveo/logger');
logger.configure({
transport: 'native',
metaSerializer: 'json-stringify-safe',
format: '{datetime} {pid} {ctx.requestId} [{level}] [{full-tag}] {message} {meta}'
})
Parameters available for formatter string:
Logging to STDOUT stream in logstash format. Settings:
const logger = require('./app/components/logger');
logger.configure({
transport: 'logstash',
prettyPrint: true
})
Logging to STDOUT stream in one line format by template string. Settings:
const logger = require('@noveo/logger');
logger.configure({
transport: 'native-colorized',
level: 'silly',
useTimezone: true,
applicationId: 'app-name',
format: '{datetime} {pid} {ctx.requestId} [{level}] [{full-tag}] {message} {meta}',
dateFormat: 'DD.MM.YYYY HH:mm:ss.SSS',
colors: {
error: 'red',
warn: 'yellow',
silly: 'magenta'
},
matches: {
green: 'request:',
bgRed: /auth/i
}
});
const log = logger.getLogger('colorized');
log.info('Info');
log.warn('Warning');
log.error('Error');
log.debug('Debug');
log.silly('Silly');
log.info('Start request: /user/login');
log.error('Some problem with AUTH man!');

Logging to mongodb collection. Settings:
localhost:27017){poolSize: 2, autoReconnect: true})logs)const logger = require('@noveo/logger');
logger.configure({
transport: 'mongo',
format: '{datetime} {pid} {ctx.requestId} [{level}] [{full-tag}] {message} {meta}',
expireAfterSeconds: 5
})
winston x 4,410 ops/sec ±3.48% (75 runs sampled)
bunyan x 4,090 ops/sec ±1.96% (77 runs sampled)
noveo x 4,684 ops/sec ±2.00% (61 runs sampled)
pino x 4,044 ops/sec ±7.33% (55 runs sampled)
Benchmark: ""noveo"" is the fastest.
The repo contains two special examples ./examples/logger-1 and ./examples/logger-2.
The ./examples/logger-1 contains sources example of noveo-logger
usage approach based on Andrey Dergaev's opinion.
The ./examples/logger-2 contains sources example of noveo-logger
usage approach based on my (Alexander Dobrodiy) opinion.
Run ./examples/logger-1
node ./examples/logger-1
Run ./examples/logger-2
node ./examples/logger-2
As Andrey is a tech lead, please, use his approach, not my! =) Maybe anytime we would try my approach in any microservice.
Please use such log levels
If you are developing a library, think it is better to use debug module or not?
FAQs
Lightweight, customizable and flexible logger module. :rocket: :zap:
We found that @noveo/logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.