Clrlog#
Lightweight colorful JavaScript application logger with stack trace and logfile support for node.js##
Changes in version 1.6#
- LOG_CUSTOM_VARIABLES allow tracing by also setting TRACE=true when debugging
- Logging messages contain an ISO date string as default
- Logging message type is always exposed [message], [success], [warning], [error]
Changes in version 1.4#
Log level changes##
-
Now the default log level is error & warning. Log
message
andsuccess
is disabled by default. It can be enabled again by setting the logLevel (logLevel='error,warning,success,message'
) -
Any log message can be enabled temporary by
-
- A) via process.env.DEBUG=true or
-
- B) via context based environment variable which can be assigned to constructor
Activation switch changes##
Clrlog has now a new property inside the constructor.
An env variable (process.env.CUSTOM_VARIALBE
) can be registered (e.g by starting the node app CUSTOM_VARIALBE=true node app.js
)
which enables any log level in the specific context for a better app behave logging.
How to use#
Instal Clrlog via npm
npm install clrlog
Require the Clrlog class
var Clrlog = ;
To give log messages color set global.DEBUG=true or run application in node.js's debug mode
processenvDEBUG = true; // or on startup DEBUG=true node app.js
Or create a file named debug
in applications root folder
Clrlog can be used as a function
;
Or as an object of the Clrlog class (The logger can be registered to a process.env property to enable logging for different purposes)
var myClrlog = "I support logging into logfiles too" 'success' __dirname + '/application.log' 'MY_CUSTOM_LOG'; myClrloglogLevel = 'error'; myClrlog; myClrlog;
Set custom log levels for a single logmessage type
myClrloglogLevel = 'error';
Or set log levels for multiple log message types
myClrloglogLevel = 'error,warning,success';
The logs are stored in the following format
Sat Apr 05 2014 [...] | SUCCESS ᑀ And hold log instances for more complex logging purposes Sat Apr 05 2014 [...] | SUCCESS ᑀ The current loglevel is message,success Sat Apr 05 2014 [...] | MESSAGE ᑀ This message goes into the logfile Sat Apr 05 2014 [...] | SUCCESS ᑀ This line goes into the logfile too Sat Apr 05 2014 [...] | SUCCESS ᑀ { "I": "can", "log": "Objects too" }
Full working example (demo/demo.js)#
{ "use strict"; // Enable global.DEBUG for colorful logging purposes // OR colorize logging when node is started in debug mode // global.DEBUG = true; // // A file named debug was created in applications root folder // so global.DEBUG is automatically set to true // Fetch Clrlog var Clrlog = ; //////////////////////////////////////////////////////// /////Call Clrlog like a plain old javascript funtion///// //////////////////////////////////////////////////////// ; ; ; ; // Object Logging ; // Save log messages in a file ; // Show stack trace behind logmessage ; //////////////////////////////////////////////////////// /////Call Clrlog as an object for more comples stuff///// //////////////////////////////////////////////////////// var myClrlog = "And hold log instances for more complex logging purposes" 'success' __dirname + '/application.log'; // LogLevel can be set on custom purposes myClrloglogLevel = 'error'; // Only errormessages myClrloglogLevel = 'warning'; // Only warnings myClrloglogLevel = 'success'; // Only success myClrloglogLevel = 'message'; // Only messages // Combined log levels are possble too myClrloglogLevel = 'error,warning'; myClrloglogLevel = 'error,warning,success'; myClrloglogLevel = 'message,success'; // Loglevel settings example myClrloglogLevel = 'message,success'; myClrlog; myClrlog; myClrlog; myClrlog; };
Author: Clrlog was written by Bernhard Bezdek
Released under MIT License
Dependencies###
node.js file system api