benpriebe/logf — pull request #2 by gerrod (2013-07-04 04:36:20+00:00)
Title: Fix off/on, add stacktrace

There is a bug in the old code where if you assign the logger somewhere and then try to turn it off, it doesn't work. For example:

system.log = log.addType("sys", "green", "log");
log.off("sys");

The logger will never turn off because the system.log has a direct reference to the log implementation, rather than the wrapper inside the logger. This is now fixed by checking if the log is enabled before writing the log statement. Additionally, this is also faster, since it doesn't generate a new log method for every call.

I've also added an option called `includeStack` when creating a logger. If set to `true`, this will now show a stack trace after each log statement. Handy for warnings and errors which otherwise don't show the stack trace (except via the error object which is not always present).

In retrospect, I'm not sure if this will work in other browsers, but works fine in chrome.