-
Notifications
You must be signed in to change notification settings - Fork 84
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
allow for custom logging #108
base: master
Are you sure you want to change the base?
Conversation
@archie Chime in? |
Why can't you use that one single logFunction provided by no-kafka and split it into several functions by the log level which is the first parameter passed to it? |
Didn't know that's how the default logger worked, documentation isn't great. If that works and we provided some examples in the README that might be an option. But it still get's really ugly because of the |
I think But that's just my 💭 |
Real pluggable logging with the string parsing would be a joy. |
+1 for replaceable logger instance. If not at least it'd be great if we could add documentation on how to replace each of the log functions. Let me know if I can help with anything. |
+1 BTW, @RXminuS there is a small conflict |
I wrote a small dedicated logging function which you can pass in with the current options and plays nice with kafka (logger is a bunyan instance): /**
* A log function that can be used by no-kafka
* @param {string} messageLevel The level at which the message is logged
* @param {string} message The actual message
* @return {undefined} Returns void
*/
function kafkaLogger(messageLevel, message) {
// The no-kafka logging library uses a log function that can take
// a variable number of arguments
// We concatenate all extra arguments and use this as the bunyan message
let args = [...arguments];
message = args.slice(1).join(' ');
switch (messageLevel) {
case 'TRACE':
logger.trace(message);
break;
case 'DEBUG':
logger.debug(message);
break;
case 'WARN':
logger.warn(message);
break;
case 'ERROR':
logger.error(message);
break;
case 'LOG':
default:
logger.info(message);
break;
}
} |
We use bunyan for our logging needs but no-kafka only allowed us to send in 1 logFunction. This meant that we couldn't use log levels properly.
I've tried to remedy this by allowing you to pass in any object which overrides the standard logging functions. It's not as pretty as I would like it to be but I favoured backwards compatibility over my OCD ;-) Test could probably be expanded a bit more but think this covers the basics. README updated accordingly.
I haven't tested all the logging libraries, just bunyan but now my output looks beautiful :-) What do you think...worth merging?