pimterry / loglevel

:ledger: Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
MIT License
2.62k stars 157 forks source link

Record of log #59

Closed orderamidchaos closed 10 years ago

orderamidchaos commented 10 years ago

Is there any way to send the error message simultaneously to a variable for generating a bug report?

pimterry commented 10 years ago

There is not, but you can add this fairly easily yourself with the plugin API: https://github.com/pimterry/loglevel#plugins. For the reasons described in there, I don't want to add this to loglevel directly.

Assuming that by sending to a variable you mean calling another function with it, you could do this yourself with something like:

// Your code:
var errorMessageListener = function (message) {
    // do something with the message
};

// Plugin:
var originalFactory = log.methodFactory;
log.methodFactory = function (methodName, logLevel) {
    var rawMethod = originalFactory(methodName, logLevel);

    return function (message) {
        errorMessageListener(message);
        rawMethod(message);
    };
};