logro
Handy logger impl.
Last updated 4 months ago by pateketrueke .
MIT · Original npm · Tarball · package.json
$ cnpm install logro 
SYNC missed versions from official npm registry.

:tada: logro Build Status NPM version Coverage Status Known Vulnerabilities

Handy logger impl.

Built on-top of bole to provide ready to use logging:

const log = require('logro').createLogger(__filename);
log.info('Just testing');

It also comes with simple formatter for the CLI:

$ echo '{"foo":"bar","time":1560577967962}' | logrof
#  12:52:47  { foo: 'bar' }

How it works?

By design, logro messages are sent to the stderr:

$ node main.js 2>&1 | logrof
#  1:22:37  INFO main.js { hostname: 'dev.local', pid: 62525, evt: 'Just testing' }

Most methods receive a message and some data, otherwise an error with some data, etc.

Last argument is used as identity for the ongoing message, on all methods.

Quiet methods (derived from bole):

  • info(msg[, data[, guid]]) — Just info; hidden on production
  • debug(msg[, data[, guid]]) — Debug info; shown during test only
  • warn(msg[, error[, guid]]) — Relax warnings; hidden from stdout
  • error(msg[, error[, guid]]) — Regular/relax errors; not critical, hidden

If warn/error receives an instance of Error, a proper failure/exception will be raised, respectively.

Loud methods:

  • failure(err[, type[, guid]]) — Real warnings!
  • exception(err[, msg[, data[, guid]]]) — Fatal errors :bomb:

Both methods always print to the stdout during development to help, the default level is info.

Log levels are set as follows:

  • process.env.NODE_ENV === 'production' — set error level
  • process.env.NODE_ENV === 'test' — set debug level
  • process.env.REMOVE_LOG === 'true' — disable all logs

Formatting

Pipe your logs to logrof in order to give them some format, it will ignore non JSON objects from the stream.

Recognized fields are: ts, time, ns, name and level.

Options:

  • --quiet — Non JSON objects are not longer printed
  • --no-color — Disable colors on formatting from output

Otherwise, the default output is JSON, always.

Public API

  • new Logro(name) and Logro.createLogger(name) — Creates a new logro instance, name can be a filepath.
  • Logro.setForbiddenFields(fromConfig) — List of fields to be ignored from data objects; also Logro.clean() is affected by this.
  • Logro.getExpressLogger() — Returns a middleware function for easy logging, it also setup req.log as helper.
  • Logro.getLogger(name) — Returns a bole instance.
  • Logro.format(message[, data[, now]]) — Returns the message formatted for CLI usage: [timestamp] [message] (data is optional)
  • Logro.logger(message) — Print formatted messages to the stdout.
  • Logro.inspect(message) — Print formatted messages to the stdout; ignored if process.env.NODE_ENV === 'test'
  • Logro.clean(data[, fields]) — Safely clone and remove fields from any given object, it also removes those set by setForbiddenFields() calls.

Current Tags

  • 0.1.9                                ...           latest (4 months ago)

19 Versions

  • 0.1.9                                ...           4 months ago
  • 0.1.8                                ...           6 months ago
  • 0.1.7                                ...           6 months ago
  • 0.1.6                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
  • 0.1.2                                ...           a year ago
  • 0.1.1                                ...           a year ago
  • 0.1.0 [deprecated]           ...           a year ago
  • 0.0.9                                ...           a year ago
  • 0.0.8                                ...           2 years ago
  • 0.0.7                                ...           2 years ago
  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (3)
Dev Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |