-
Notifications
You must be signed in to change notification settings - Fork 944
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
Debug through logger's debug function #239
Comments
hmm.. a super primitive example works for me: // deps
var winston = require('winston')
var Debug = require('debug');
Debug.log = winstonWrapper;
var debug = Debug('myapp');
// create your winstonn logger.. whatever
var logger = new winston.Logger({
transports: [
new winston.transports.Console({ raw: true })
]
})
// debug some stuff
debug('hello world')
setInterval(work, 250);
var n = 0;
// do work
function work() {
debug('doing work (%d)', ++n)
}
// the magic happens here
function winstonWrapper() {
logger.log.apply(logger, ['info'].concat(arguments));
} yields: $ DEBUG=* DEBUG_COLORS=0 node winston-example.js
{"level":"info","message":"{ '0': 'Tue, 08 Dec 2015 17:51:15 GMT myapp hello world' }"}
{"level":"info","message":"{ '0': 'Tue, 08 Dec 2015 17:51:15 GMT myapp doing work (%d)',\n '1': 1 }"}
{"level":"info","message":"{ '0': 'Tue, 08 Dec 2015 17:51:15 GMT myapp doing work (%d)',\n '1': 2 }"}
{"level":"info","message":"{ '0': 'Tue, 08 Dec 2015 17:51:15 GMT myapp doing work (%d)',\n '1': 3 }"}
{"level":"info","message":"{ '0': 'Tue, 08 Dec 2015 17:51:16 GMT myapp doing work (%d)',\n '1': 4 }"}
{"level":"info","message":"{ '0': 'Tue, 08 Dec 2015 17:51:16 GMT myapp doing work (%d)',\n '1': 5 }"}
{"level":"info","message":"{ '0': 'Tue, 08 Dec 2015 17:51:16 GMT myapp doing work (%d)',\n '1': 6 }"}
^C you may be running into versioning issues with module_using_debug though... |
Thanks, it seems to be working. I was misleaded by some unexpected output. Now I am looking for a way to turn off debug's timestamp, since my logger already timestamps lines. Debug.log = Winston.debug.bind(Winston); |
Answering to myself: just need to replace debug's formatArgs function... |
besides implementation ( and because i was thinking to use same technique ) .. is these a right approach? binding/composing debug through winston i mean. thanks |
After using it for a while, I'd say it's not a perfect solution. It has at least 2 problems:
|
@bragma @stephenmathieson middleware should solve this: #370 |
^Feel free to join in on convo |
Did this happen? Having trouble finding it anywhere in the docs for 3.1 |
Pardon me if this has already been answered. I know "debug" is not a logger and I respect that. I do not want to log with debug, I'd like debug to output in my logs instead. :-)
Specifically I'd like all third party modules using the ubiquitous "debug" to log through Winston's debug function. It's a matter of consistency turning log levels on/off dynamically.
Is it possible?
I've tried to leverage node's module caching in this way:
It's not working... :-(
The text was updated successfully, but these errors were encountered: