jetlog

1.0.60 • Public • Published

JetLog

Streamed logger with multiple simltaneous output options.

The intention of this module is to allow pushing the log data to an API, some file and still be able to see the data in stdout.

Streams are based on scramjet so you can use any transforms you like on your streams.

Default output

No colors, no fancy line drawing, nothing yet really - just a simple and parsable log output...

2018-06-29T15:07:37.339Z jetlog [info] defaultOutput(simple.js:52) Message1
2018-06-29T15:07:37.339Z jetlog [log] defaultOutput(simple.js:53) Message2
2018-06-29T15:07:37.339Z jetlog [error] defaultOutput(simple.js:54) Message3!

Usage

Simple version:

const logger = require('jetlog');
jetlog.log("Some message", {some_extra: data});

More complex version:

const {JetLog, Entry} = require('jetlog');
 
const logger = new JetLog({})
    .catch(e => new Entry("Invalid log entry", e)); // remember to handle errors
 
logger
    .use("my-decorator-module") // use stream modules to add data to logs
    .toJSONStream() // use `scramjet` transforms to do anything you like to your logs
    .tee(fs.createWriteStream("/var/log/myapp.log")) // push log to file
 
logger
    .filter(({level}) => level >= 3) // use scramjet functions on entries
    .stringify(myParser) // stringify your log
    .pipe(process.stdout); // pipe anywhere you like
 
logger
    .level("warn") // level will be assigned to the chained method
    .use("my-reporter") // you can use own reporters
    .pipe(process.stderr);

Environment control

Jetlog's default logger (the one exposed as module.exports) behavior can be changed using the following environment variables:

  • JETLOG_REPORTER - choose reporter module "./lib/entry-reporter" by default.
  • JETLOG - boolean - set to "0" to disable stdout.
  • JETLOG_FILTER - only log if Entry matches any of the words (space separated).

API

  • module.exports : JetLog - the default export is a JetLog instance piped to stdout using the standard log reporter.
  • module.exports.getLog(name, pipeToOutput, reporter, filterArray) - a facilitation method for creating loggers
  • module.exports.JetLog - the main logger class is exported

JetLog class

JetLog class implements the following methods:

Logging methods are as follows in the following order:

JetLog Entries

Each log message is turned to a stream object.

Props:

See more about Entry here

License

JetLog is MIT licensed.

Package Sidebar

Install

npm i jetlog

Weekly Downloads

3

Version

1.0.60

License

MIT

Unpacked Size

263 kB

Total Files

35

Last publish

Collaborators

  • patu
  • scramjetorg
  • michalcz
  • stoq