-
Notifications
You must be signed in to change notification settings - Fork 10
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
lib: support different loggers #224
Conversation
lib/logger.js
Outdated
const set = l => logger = l; | ||
const get = () => logger; | ||
|
||
const isDebug = () => logger && logger.debug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find these names misleading, something like hasDebug
etc would be better, IMO. I'd expect isDebug
, isVerbose
and alike to report the current logging level, which is not the case with these checks because these methods will be present in virtually every logger regardless of the logging level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the actual reason I named them as such, I was mislead by issue in winston
that actually suggested to check level this way.
I haven't found a good way to get debug level out of winston beside .level
which gives a string, that's disappointing. Lucky enough bunyan returns a number which is a lot better. I guess we will allow user to provide a callback to check current log level and I'll write proxies for winston and bunyan to simplify their usage.
'Run `npm install` in order to build it, otherwise you will get ' + | ||
'poor performance.' | ||
); | ||
if (logger.isWarn()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't possible to replace the logger before this statement will be executed, so it will always use the default logger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aqrln yeah, missed that. Should we set console
as default logger or always log to console here?
Adds functionality to specify logger that will be used. By default all logs are ignored. Fixes: #102
2f5aa8f
to
2f5b62d
Compare
I'd like the logger to have method's like: |
@nechaido It already has those methods and decides by itself whether he should log or drop the message. The need in methods like |
@lundibundi this could be achieved by passing a function to logger which will do the preparation and then return the string to be logged. |
@lundibundi, can't you make a wrapper (adapter) in our library which will check the logger level before the preparation, to avoid boilerplate checking like the one @nechaido mentioned? |
@belochub I can do that but I see no reason for that complexity, whether we write |
@lundibundi and what about:
Looks ok for me Forgot about creating a function to be passed. |
@lundibundi, what you said in #224 (comment) wasn't at all what I proposed to do. |
@lundibundi, what I proposed will make if (logger.isDebug()) logPacket(packet); look like logger.get().debug(packet); or even logger.debug(packet); |
@lundibundi, yeah, something like that. |
@belochub but its only usage are those 3 calls in connection.js and I'm not sure if it is plausible to implement it solely for those usages? Also I can move |
@lundibundi ping |
@aqrln I'm waiting for the decision of our team, whether this is a good solution or not. We even got the slack vote which has apparently been flooded by github bot. |
Enables users to specify logger they want to use with our library. Also adds simple proxy to
console
.As discussed in #102 I extract logger fuctionality to a different PR.
Also I'd like to add a few tests for console logger, but I don't know how to better implement it, as I don't think that either redirecting console output during the test or just checking stdout is a good solution, can someone suggest a solution?