Commit 06ff4084 authored by Yash Soni's avatar Yash Soni

Updated readme content

parent c00a00b0
# easy-logging
# # easy-logging
Easily write beautiful JSON formatted logs with colors for each level.
\ No newline at end of file
#### Easily write beautiful JSON formatted logs with colours for each level.
- - - -
#### Example:
#####- Initialisation:
```
var Logger = require('easy-logging');
/**
* Logger() is a constructor with 2 params -
* a MANDATORY 'TAG' param and an OPTIONAL 'LEVEL' param
* TAG - log instance identifier
* LEVEL - acts as a logs filter. Accepted values are ["INFO","DEBUG","WARN","ERROR","TRACE"]
*/
var logInstance = new Logger("MyLoggerTag", "trace");
```
#####- Usage:
Each of the Logger APIs take first param as a message - it is essential to pass meaningful value to this parameter.
After message parameter, follows a variable length argument - meaning you can send as many extra as you want to log. Example for this is shown above.
```
// Logging Errors data
logInstance.error("I'm an error!");
// Logging Warning data
logInstance.warn("I'm a warn!", {something: "anything"});
// Logging Info data
logInstance.info("I'm an info!", 1, 2, 3, 4, 5);
// Logging Debug data
logInstance.debug("I'm a debug!", ["Hello","World!"]);
// Logging Trace data
logInstance.trace("I'm a trace!");
```
Apart from the above mentioned basic Logging methods, we have two special methods `entering & exiting` that will help developers write `detailed-logging-enabled` applications.
Here's the first parameter is always methodName - this helps us marking ENTRY or EXIT to that method. Second parameter is again a variable length argument - this is mainly aimed to log method parameters while Entering and Exiting the method.
Example:
```
// Logging Method Entry with Entry params
logInstance.entering("testMethod", {"hello":"world"}, {"timeStamp":"1234567890"}, "This is another parameter that I want to be logged...");
// Logging Method Exit with Exit params
logInstance.exiting("testMethod", {"bye":"bye"});
```
Screenshots:
![](README/Screenshot%202019-02-13%20at%208.04.53%20PM.png)
![](README/Screenshot%202019-02-13%20at%208.06.07%20PM.png)
That’s it, simple and easy to use - Colourful Logging Library!
Cheers! 🍻
\ No newline at end of file
......@@ -34,31 +34,31 @@ const Logger = function (tag, level){
_isValidLogLevel(this.level);
// Logging functions
this.error = function(msg, logParams){
this.error = function(msg, ...logParams){
if(LogLevelValues[this.level] >= LogLevelValues.ERROR)
log(colorSchema.error(getJSONLogString("ERROR", this.tag, msg, logParams)));
};
this.warn = function(msg, logParams){
this.warn = function(msg, ...logParams){
if(LogLevelValues[this.level] >= LogLevelValues.WARN)
log(colorSchema.warn(getJSONLogString("WARN", this.tag, msg, logParams)));
};
this.info = function(msg, logParams){
this.info = function(msg, ...logParams){
if(LogLevelValues[this.level] >= LogLevelValues.INFO)
log(colorSchema.info(getJSONLogString("INFO", this.tag, msg, logParams)));
};
this.debug = function(msg, logParams){
this.debug = function(msg, ...logParams){
if(LogLevelValues[this.level] >= LogLevelValues.DEBUG)
log(colorSchema.debug(getJSONLogString("DEBUG", this.tag, msg, logParams)));
};
this.entering = function(methodName, logParams){
this.entering = function(methodName, ...logParams){
if(LogLevelValues[this.level] <= LogLevelValues.TRACE)
log(colorSchema.entering(getJSONLogString("TRACE", this.tag, methodName, logParams, "ENTRY")));
};
this.exiting = function(methodName, logParams){
this.exiting = function(methodName, ...logParams){
if(LogLevelValues[this.level] <= LogLevelValues.TRACE)
log(colorSchema.exiting(getJSONLogString("TRACE", this.tag, methodName, logParams, "EXIT")));
};
this.trace = function(msg, logParams){
this.trace = function(msg, ...logParams){
if(LogLevelValues[this.level] <= LogLevelValues.TRACE)
log(colorSchema.trace(getJSONLogString("TRACE", this.tag, msg, logParams)));
};
......
......@@ -30,11 +30,7 @@ function getJSONLogString(level, tag, msg, logParams, traceMeta) {
} else {
result.msg = msg;
}
if(logParams instanceof Object && !(logParams instanceof Array)) {
Object.assign(result, logParams);
} else {
result.extraParams = logParams;
}
result.extraParams = logParams;
return JSON.stringify(result);
}
......
var Logger = require('../index');
var instance = new Logger("MyTag", "trace");
instance.entering("testMethod", {"hello":"world"});
instance.error("I'm an error!");
instance.trace("I'm a trace!");
instance.info("I'm an info!");
instance.debug("I'm a debug!", ["Hello","Yash"]);
instance.warn("I'm a warn!", {something: "anything"});
instance.exiting("testMethod", {"hello":"world"});
\ No newline at end of file
/**
* Logger() is a constructor with 2 params -
* a MANDATORY 'TAG' param and an OPTIONAL 'LEVEL' param
* TAG - log instance identifier
* LEVEL - acts as a logs filter. Accepted values are ["INFO","DEBUG","WARN","ERROR","TRACE"]
*/
var logInstance = new Logger("MyLoggerTag", "trace");
// // Logging Errors data
// logInstance.error("I'm an error!");
// // Logging Warning data
// logInstance.warn("I'm a warn!", {something: "anything"});
// // Logging Info data
// logInstance.info("I'm an info!", 1, 2, 3, 4, 5);
// // Logging Debug data
// logInstance.debug("I'm a debug!", ["Hello","World!"]);
// // Logging Trace data
// logInstance.trace("I'm a trace!");
// Logging Method Entry with Entry params
logInstance.entering("testMethod", {"hello":"world"}, {"timeStamp":"1234567890"}, "This is another parameter that I want to be logged...");
// Logging Method Exit with Exit params
logInstance.exiting("testMethod", {"bye":"bye"});
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment