@node-lightning/logger
TypeScript icon, indicating that this package has built-in type declarations

0.28.0 • Public • Published

Node-Lightning Logger

Logger for Node-Lightning modules that supports multi-transport, multi-area+instance logging using standard util.format sprintf value formatting.

Getting Started

npm install @node-lightning/logger

To use the module you will need to create an area logger and include an optional instance identifier:

const { manager } = require("@node-lightning/logger");

const area = "TEST";
const instanceId = "12345678";
const log = manager.create(area, instanceId);

Then you can write debug, info, warn, and error messages by passing a message an a variadic number of values. You can pass text, values, sprintf syle strings, or a string and a list of values that will be appended to the end of the message.

log.debug("test");
log.info("hello");
log.warn("i'm warning you");
log.error("something went bad");
log.error(new Error("booooom"));
log.info("some stuff %j", { ok: true, foo: "bar" });
log.info("some values", 1, 2, 3, 4);
log.info("using %s formatting", "sprintf");

The above message should look similar to:

2019-07-22T13:28:37.854Z [DBG] TEST 12345678: test
2019-07-22T13:28:37.855Z [INF] TEST 12345678: hello
2019-07-22T13:28:37.855Z [WRN] TEST 12345678: i'm warning you
2019-07-22T13:28:37.855Z [ERR] TEST 12345678: something went bad
2019-07-22T13:28:37.856Z [ERR] TEST 12345678: Error: booooom
    at Object.<anonymous> (/code/go/src/github.com/altangent/node-lightning/packages/logger/test.js:9:11)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
2019-07-22T13:28:37.856Z [INF] TEST 12345678: some stuff {"ok":true,"foo":"bar"}
2019-07-22T13:28:37.856Z [INF] TEST 12345678: some values 1 2 3 4
2019-07-22T13:28:37.856Z [INF] TEST 12345678: using sprintf formatting

Output

The default instance of the logger will output to:

  • console
  • node-lightning.log file located at the root of the application runtime

Package Sidebar

Install

npm i @node-lightning/logger

Weekly Downloads

89

Version

0.28.0

License

MIT

Unpacked Size

151 kB

Total Files

57

Last publish

Collaborators

  • bmancini55