Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using appropriate console function and displaying callee of logger #14

Open
gpicavet opened this issue Jun 17, 2015 · 3 comments
Open

Comments

@gpicavet
Copy link

Hello, thank you for this cool library !

Just 2 little things :
-It would be nice to use the appropriate console function(error, info, log) according to the log level.
-Displaying the line where the logger has been called (using the stack)

As an exemple, here is an extension i did myself (sorry i'm not a javascript expert!) :

Log4JS.SafariJSConsoleAppender.prototype.doAppend= function (loggingEvent) {
        var style;
        var func = null;
        if (loggingEvent.level.toString().search(/ERROR/) != -1) {
            style = 'color:red';
            func = "error";
        } else if (loggingEvent.level.toString().search(/FATAL/) != -1) {
            style = 'color:magenta';
            func = "error";
        } else if (loggingEvent.level.toString().search(/WARN/) != -1) {
            style = 'color:yellow';
            func = "warn";
        } else if (loggingEvent.level.toString().search(/DEBUG/) != -1) {
            style = 'color:cyan';
            func = "log";
        } else if (loggingEvent.level.toString().search(/INFO/) != -1) {
            style = 'color:green';
            func = "info";
        } else if (loggingEvent.level.toString().search(/TRACE/) != -1) {
            style = 'color:blue';
            func = "log";
        } else {
            style = 'color:grey';
            func = "log";
        }

        if(!console[func]) {
            func = "log";
        }

        var realLine = "";
        var stack = new Error().stack;
        var stackStr = stack.split("\n");
        for(var i in stackStr) {
            var call = stackStr[i];
            if(call.indexOf("Log4js")==-1 && call.indexOf("Logger")==-1) {
                realLine = call;
                break;
            }
        }

        console[func].apply(console, ["%c "+this.layout.format(loggingEvent) + " "+realLine, style]);
    };

Kind regards

@ghost
Copy link

ghost commented Jun 18, 2015

I would also like for there to be default context based colours for log entries that appear in web console(not to be confused with the browser console or shell) but that should be its own(Issue) appender or plugin for an appender. As that would output _raw_ in a shell(terminal).

I know at least in FF you can log directly to the web console without using console.* methods.

I thought I'd mention that the log methods should be preset(binded?) not set inside doAppend.

js-logger has the right idea on this.
See here for an example.

@ghost
Copy link

ghost commented Jun 21, 2015

Bump. This is clearly a bug. Your library doesn't use console.* methods! If you mean to compete with lets say log4javascript or even js-logger then this issue should definitely be fixed ASAP. 👍

@stritti
Copy link
Owner

stritti commented Jun 30, 2015

Many thanks for the improvements. I will have a look on them, but also any pull requests are welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants