alog4js
This is a wrappers of the log4js-node, and we add functions for dynamic layout setting.
The init function parameter is an Array of domain list, and the domain list only need to set the top level
We can use its sublevel without further setting, thanks for Gareth Jones(log4js-node)
prerequisite
nodejs 10.12.0 or bigger.
installation
npm install alog4js
usage
Initialize:
var log4js = ;log4jsvar logger = log4js; //now you can use the logger with default tag
RUN with argument:
LEVEL=info SHOW=* node main.js
Dynamic Layout setting:
Implement your REST API and run these code properly.
And your can update server log layout setting online.
- dynamic change log level
loggerlevel = 'debug'; // ['trace','debug','info','warn','error','fatal']
- dynamic change specific log domain with log level
//show is the variable format like Run Argument SHOW, check Example for further informationlog4js; // log4js.update("DB.pool", "trace");
- trace the log by file
less -R trace.log
or install the colortail (recommended)
colortail -f trace.log
Demo
run demo on your machine alog4js-demo
or look demo video on youtube
Example
- Default run with LEVEL=info, SHOW=*
node examples/main.js
- set log level at 'debug', and show log belongs 'DB'.
LEVEL=debug SHOW=DB node examples/main.js
- set log level at 'trace', and show log belongs 'DB.index' only.
LEVEL=trace SHOW=DB.index node examples/main.js
- set log level at 'error', and show log belongs 'default' or 'DB' or 'modules.insert'.
LEVEL=error SHOW=default,DB,modules.insert node examples/main.js
- set log level at 'warn', and show log belongs 'default' or 'DB.index'.
LEVEL=warn SHOW=default,DB.index node examples/main.js
License
The original log4js-node was distributed under the Apache 2.0 License, and so is this. I've tried to keep the original copyright and author credits in place, except in sections that I have rewritten extensively.