darrylwest/simple-node-logger

setLevel not taking effect

Opened this issue · 2 comments

I was just checking how the dynamic log level change would work and tried below code:

const appLogger = require('simple-node-logger').createSimpleLogger();

appLogger.setLevel('debug');

appLogger.debug('appLogger:debug');
appLogger.info('appLogger:info');
appLogger.warn('appLogger:warn');
appLogger.error('appLogger:error');

appLogger.setLevel('warn');

appLogger.debug('appLogger:debug  2');
appLogger.info('appLogger:info  2');
appLogger.warn('appLogger:warn  2');
appLogger.error('appLogger:error  2');

The expected output was:

16:23:31.737 DEBUG appLogger:debug
16:23:31.737 INFO appLogger:info
16:23:31.737 WARN appLogger:warn
16:23:31.737 ERROR appLogger:error
16:23:31.737 WARN appLogger:warn 2
16:23:31.737 ERROR appLogger:error 2

But what I get is:

16:23:31.737 WARN appLogger:warn
16:23:31.737 ERROR appLogger:error
16:23:31.737 WARN appLogger:warn 2
16:23:31.737 ERROR appLogger:error 2

So it seems the seconds setLevel also affects the statements before it. Or am I doing something wrong?
The package version is: simple-node-logger@18.12.24

Did you ever find a solution for this?

I'm using version 21.8.12

I'm seeing basically the same thing, but I don't think it has anything to do with setLevel. When I start my program, the only things that will log are ERROR level. Regardless if I call setLevel or not (level apparently defaults to 'info'). Calling getLevel reports 'info', but only error level actually logs...

Calling setLevel has no effect on the output; I still just get ERROR level things actually logging.

Any input greatly appreciated.

No, I did not find any solution and ended up switching to some other logging library.

I did not observe what you are seeing, though.