Logger Facade Console plugin for Nodejs
Simple node module to log information on console using logger facade.
This simple logger facade allows pluggin hook to execute different logging.
The plugin receives a config file with:
Level: The level configuration active for this pluggin.
Time Format: The time format using moment.js formats.
Message Format: The message format to log, the message information can use util.format parameters.
- %logger - name of current logger instance
- %time - current date time
- %level - message level
- %pid - process id
- %msg - message to log
- %metadata - additional metadata to log
How to use it
Install it:
npm install logger-facade-nodejs
npm install logger-facade-console-plugin-nodejs
Set up plugins and log in a human readable format
If you use metadata, to improve readability you may want to use prettyPrint: true
.
var Logger = ;var LoggerConsolePlugin = ; // this is the default configvar config = level: 'debug' timeFormat: 'YYYY-MM-DD HH:mm:ss' messageFormat: '%time | %logger::%level - %msg' json: false prettyPrint: false; console; var plugin = config;Logger; console; var log = Logger;log;log;log;log;log;log;log;log;log;log; console; process;
Download the code from this gist.
Set up plugins and log in a json format
var Logger = ;var LoggerConsolePlugin = ; // this is the default configvar config = level: 'debug' timeFormat: 'YYYY-MM-DD HH:mm:ss' messageFormat: '%time | %logger::%level - %msg' json: true prettyPrint: false; console; var plugin = config;Logger; console; var log = Logger;log;log;log;log;log; console; process;
Pretty print option
The pretty print option is used to ouput metadata in a json pretty print format.
Download the code from this gist.
Contributing
Bug fixes and new features are of course very welcome!
To get started developing:
- Install Grunt
- Install dependencies with
npm install
- Run the test suite with
npm test
Please accompany any Pull Requests with the relevant test cases and make sure everything else still passes :).
Credits
Shout out to @pjanuario.