log2json2stdout
This is simple logger for JavaScript programs.
- Support only 2 levels:
info
&error
because nobody in reality do not care about other levels. - All logs going to stdout, because apps is not a place where logs should be processed.
- Output in JSON, because it's really easy to parse (except TTY, where output is human readable).
- Fields in JSON object in order:
timestamp
,level
,message
, ...rest
Usage
$ node ./test.js{"timestamp":"2019-03-21T16:58:16.440Z","level":"info","message":"hello"}{"timestamp":"2019-03-21T16:58:16.442Z","level":"error","message":"world","stack":"Error: world\n at Object.<anonymous> (/home/kirill/projects/log2json2stdout/test.js:5:13)\n at Module._compile (internal/modules/cjs/loader.js:799:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:810:10)\n at Module.load (internal/modules/cjs/loader.js:666:32)\n at tryModuleLoad (internal/modules/cjs/loader.js:606:12)\n at Function.Module._load (internal/modules/cjs/loader.js:598:3)\n at Function.Module.runMain (internal/modules/cjs/loader.js:862:12)\n at internal/main/run_main_module.js:21:11"}$ node ./test.js | tee2019-03-21T16:58:10.411Z info: hello2019-03-21T16:58:10.413Z error: worldError: world at Object.<anonymous> at Module._compile at Object.Module._extensions..js at Module.load at tryModuleLoad at Function.Module._load at Function.Module.runMain at internal/main/run_main_module.js:21:11$ node ./test.js | log2json2stdout-to-tty2019-03-21T17:03:30.838Z info: hello2019-03-21T17:03:30.840Z error: worldError: world at Object.<anonymous> at Module._compile at Object.Module._extensions..js at Module.load at tryModuleLoad at Function.Module._load at Function.Module.runMain at internal/main/run_main_module.js:21:11$ cat test.jsconst logger = require logger.info const err = new Errorlogger.error
LICENSE
This library is free and open-source software released under the MIT license.