I use something like:

// top of file:
var trace = require('appConfig').getTrace(module); // returns logging
function or null

// anywhere in the file
trace && trace(some_message);

getTrace can return console.log but may also return a function that
logs to file.

On Feb 29, 12:46 am, Diogo Resende <[email protected]> wrote:
> On Wed, 29 Feb 2012 00:33:32 +0100, Phoscur wrote:
> > How is this better than:
> > function debug(msg) {
> >     if (DEBUG_ON) {
> >         console.log(msg);
> >     }
> > }
> > ?
>
> The complex logic in msg is processed (in some way) and debug is
> called. For the same behavior you need to do:
>
> function debug() {
>    if (DEBUG_ON) {
>      console.log.apply(console, arguments);
>    }
>
> }
>
> <bool>&&console.log() is faster and cleaner
>
> ---
> Diogo R.

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to