code-chunks / angular2-logger

A log4j inspired logger for angular 2.
MIT License
144 stars 41 forks source link

Debug is not printing in console. #170

Closed harikrishnan-u01 closed 7 years ago

harikrishnan-u01 commented 7 years ago

Hi, Debug is not printing in console.

I added the following logs and only 1, 3 and 4 are getting printed in console. Somehow debug is not working.

this.logger.log("1"); this.logger.debug("2"); this.logger.info("3"); this.logger.error("4");

Since logger.log has lesser priority level compared to logger.debug, since logger.log is printing, logger.debug also should print in the console right?

I am setting the following in my app.module.ts constructor: this.logger.level = Level.LOG;

Thanks, Hari

langley-agm commented 7 years ago

Extract from the main page:

0.- Level.OFF

1.- Level.ERROR

2.- Level.WARN

3.- Level.INFO

4.- Level.DEBUG

5.- Level.LOG
langley-agm commented 7 years ago

I put the extract here to better compare the results. Try using 5 instead of LOG and let me know if you get the same results. If you do please share a reproduce-able of your issue.

harikrishnan-u01 commented 7 years ago

Hi @langley-agm ,

I changed this.logger.level = 5; and its the same result.

Thanks, Hari

harikrishnan-u01 commented 7 years ago

Hi @langley-agm ,

In the logger.ts file, the debug method looks bit different from others:

`error(message?: any, ...optionalParams: any[]) {
    this.isErrorEnabled() && console.error.apply( console, arguments );
}

warn(message?: any, ...optionalParams: any[]) {
    this.isWarnEnabled() && console.warn.apply( console, arguments );
}

info(message?: any, ...optionalParams: any[]) {
    this.isInfoEnabled() && console.info.apply( console, arguments );
}

debug(message?: any, ...optionalParams: any[]) {
    this.isDebugEnabled() && ( <any> console )[ CONSOLE_DEBUG_METHOD ].apply( console, arguments );
}

log(message?: any, ...optionalParams: any[]) {
    this.isLogEnabled() && console.log.apply( console, arguments );
}`

Is there something special we have to do to enable it?

Thanks, Hari

langley-agm commented 7 years ago

Hi @harikrishnan-u01,

It looks a bit different because not all browser's implement the debug method, so if the browser doesn't have it, it'll use the log method IIRC.

As long as the browser has the console.debug method, it should work exactly the same as all other methods.

Have you make sure you aren't filtering messages with the browser's filter? In Chrome, hit F12:

image

Make sure it's set to verbose.

If that's not the issue, please provide a jsbin or jsfiddle so I can have a way to reproduce your issue if you need more support.

harikrishnan-u01 commented 7 years ago

Hi @langley-agm ,

As you pointed out, the issue was that my chrome browser was filtering messages with Info. When I changed it to Verbose, it started printing the debug logs.

Thanks for pointing it out.

But the problem is that this library is not working in production build. So I had to revert the code. I had raised this as part of https://github.com/code-chunks/angular2-logger/issues/75.

You can close this issue.

Thanks, Hari

langley-agm commented 7 years ago

Is not that is doesn't work in production, it doesn't work in the default ng cli configuration for production mode, extra configuration is needed for it to work, just like rxjs, problem is no one has shown the actual error, I cannot give support based on the obfuscated error code prints.