1.6.1 • Published 8 years ago

ezlogger v1.6.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

ezLogger

Installation

npm install ezLogger

Initialize

After initialize all project's console.log will change.

var ezLogger = require("ezlogger");
ezLogger(__dirname + "/log.txt");
console.log("That's it!");
// ezLogger(FileName,Pattern);
// default pattern is
// "[date] [file]:[line] [message]"

Note: Pattern is updated in 1.3.0 to function

ezLogger("./log.txt", function(file, line, message) {
   return "{3} {0}:{1} {2}".format(file, line, message, Date.simple());
});

log.txt file appeared.

15/06/2015 15:39:31 app.js:3 That's it!

ezFormat

You can use console.log with ezFormat.

// initialize
var ezLogger = require("ezlogger");
ezLogger(__dirname + "/log.txt");
var isConnected = true;
var myObject = {
    Life: 1,
    Tools: [
        {
            Name: "Jacket",
            Weight: 3,
        }
    ]
};
console.log("Server connection: {0:bool}", isConnected);
console.log("Returned object {0:json:4}", myObject);

Dynamic File

Initialize ezlogger with function

var ezLogger = require("ezlogger");
ezLogger(function() {
    // you can use Date.simple.more too. It will come with ezlogger
    return __dirname + "/log." + Date.simple.more() + ".txt";
});
console.log("That's it!");

log.15.06.2015.txt file appeared.

15/06/2015 15:39:31 app.js:5 That's it!

Trace Level

If you want to create own logger function, you probably get wrong location because of trace level is 1 default. So use logTrace

function myLoggerError(message) {
    console.log("[ERROR] {0}", message);
}

myLoggerError("test"); // prints 15/06/2015 15:39:31 test.js:2 [ERROR] test
// but it shouldn't be test.js:2 it should be test.js:5

with logTrace

function myLoggerError(message) {
    console.logTrace(2, "[ERROR] {0}", message);
}

myLoggerError("test"); // prints 15/06/2015 15:39:31 test.js:5 [ERROR] test

add ezFormat to own function

function myLoggerError(message) {
    if (arguments.length > 1) {
          message = String.prototype.format.apply(message, Array.prototype.slice.call(arguments, 1));
    }
    
    console.logTrace(2, "[ERROR] {0}", message);
}

myLoggerError("test! {0}", 1); // prints  15/06/2015 15:39:31 test.js:9 [ERROR] test! 1

1.6.0 Features

  • console.error added
  • console.errorTrace added
  • handleUncaughtExceptions added.
var ezLogger = require("ezlogger")();
ezLogger.handleUncaughtExceptions();
1.6.1

8 years ago

1.6.0

8 years ago

1.5.2

8 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.0

9 years ago

1.3.0

9 years ago

1.2.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago