indexzero/winston — Issue #59: improve "Extending another object with Logging functionality"
Author: jdonnerstag
Created: 2011-10-16 13:04:40+00:00
State: open

Hi,

I'm trying to migrate an existing app to use winston. In that app there is code like the one below which is very similar to what winston.extend(myObject) does, but with the difference that the context is automatically set based on a myObject property. In the case below it is the transaction.uuid. I understand that I'm manually able to set the context, but I'd like to have it in a single place and instead of setting the context with every log statement.

for (var key in logger) {
if (key.match(/^log\w/)) {
Connection.prototype[key] = (function (key) {
return function () {
var args = [ (this.transaction ? this.transaction.uuid : this.uuid) + " " ];
for (var i=start, l=arguments.length; i