clintandrewhall/node-foursquare

is log4js strictly necessary?

RandomEtc opened this issue · 8 comments

It's quite an invasive library to import by default - we're wondering if there's a way to suppress it, either directly or via node-foursquare?

I'm actually wanting to replace it with Winston:

https://github.com/flatiron/winston

You should be able to suppress everything with configuration?

For example: https://github.com/clintandrewhall/node-foursquare/blob/master/lib/config-default.js

I may be able complete the migration to Winston this week. Is this causing an issue? You could also add a null appender or remove appenders?

The issue is that it overrides the default console - this is configurable (thanks for pointing that out) and can be restored with restoreConsole(), but only in the latest releases. Looks like node-foursquare currently requires log4js 0.3.x, which has a bug where it can only restore the log method (error etc are lost).

Winston looks good - assuming it doesn't override the default console ;) We're looking at debug which has named channels but doesn't have configurable log targets.

Just confirmed that if I uninstall 0.3.x and force node-foursquare to use log4js@0.4.1 then require('log4js').restoreConsole(); fixes my issue. In the short term (pre-Winston) if you could bump the log4js version and push a new package that would be great for us.

Happy to test the Winston integration too if you give me a heads up and point me at a git branch or tarball.

Great, thanks for that. I'll perform that migration tonight and let you know here when it's in npm.

Thanks for the offer; I'll be taking you up on that, I'm sure. :-D

Not sure if you got around to pushing another package or not. It's OK though, I figured out how to restore the console in log4js 0.3.x and the correct place to do it in my project.

Here's the workaround, before and after you require node-foursquare and instantiate the foursquare instance, do:

// remember original console methods:
var oldConsole = {};
['log','debug','info','warn','error'].forEach(function (item) {
    oldConsole[item] = console[item];
});

var foursquare = require('node-foursquare')({ /* ... params ... */ });

// restore original console methods:
['log','debug','info','warn','error'].forEach(function (item) {
    console[item] = oldConsole[item];
});

For anyone else messing with this, the restoration of the console has to happen after both the require statement and the call to make a foursquare instance.

Tom, I'm so sorry... I got wrapped up in other work. I'll get this fix
pushed ASAP.

Sincerest apologies. If you'd like to make the fix in my absence and
request a pull, I'd be happy to merge it. Otherwise, I'll get to it
tomorrow as soon as I can.

Sent from my iPhone

On Mar 1, 2012, at 12:49 AM, Tom Carden
reply@reply.github.com
wrote:

Not sure if you got around to pushing another package or not. It's OK though, I figured out how to restore the console and the correct place to do it.

Here's the workaround, before and after you require node-foursquare and instantiate the foursquare instance, do:

// remember original console methods:
var oldConsole = {};
['log','debug','info','warn','error'].forEach(function (item) {
   oldConsole[item] = console[item];
});

var foursquare = require('node-foursquare')({ /* ... params ... */ });

// restore original console methods:
['log','debug','info','warn','error'].forEach(function (item) {
   console[item] = oldConsole[item];
});

For anyone else messing with this, the restoration of the console has to happen after both the require statement and the call to make a foursquare instance.


Reply to this email directly or view it on GitHub:
#5 (comment)

Don't worry about it - I closed the issue because the workaround is adequate, especially if you're moving to Winston when you have a chance.