On the optional debug mode note, I'm a big fan of TJ's debug() module:
https://github.com/visionmedia/debug

On Wed, Jan 23, 2013 at 11:12 AM, Isaac Schlueter <i...@izs.me> wrote:

> The logging goes in the cli app, not in the reusable library. (If your
> module is both, you *might* be Doing It Wrong, at least a little bit.
> Don't feel bad, it's a common mistake that even the best of us make.)
>
> In reusable libs, there are two approaches that I've found useful.
>
> The first is to have your class emit a "log" event, with some data.
> This can then be hooked up to winston or bunyan or npmlog or
> console.error or any other random thing, as your user sees fit.  (Your
> cli app can connect this to winston, for example.)
>
> The second is to have a "debug" flag of some sort (either an
> environment var or an option passed into the module) that, if true,
> points logs at console.error, and if falsey, makes `this.log(bleah)` a
> no-op.  This is how logging is done in node core (via the NODE_DEBUG
> environment var) and also how I've done it in nopt, node-glob,
> minimatch, and a few others.  It's better when the debug messages are
> usually only interesting to you when debugging problems, but perhaps
> overly noisy for normal use.
>
>
> On Wed, Jan 23, 2013 at 9:30 AM, Geerten van Meel <klova...@gmail.com>
> wrote:
> > You could allow users to provide a user definable logger function in an
> > options object. Just define in your docs how the logging callback should
> > behave, i.e. it should be a callback function of the sorts function
> (level,
> > message, metadata).
> >
> > However, think thoroughly whether you really need to perform plain
> logging
> > (debug, info, notice) in your module. You can still return errors as your
> > first callback argument (if applicable), emit "error" events or throw
> errors
> > (but you should avoid throwing errors if possible).
> >
> > All the best,
> >
> > Geerten
> >
> >
> > On Wednesday, January 23, 2013 4:04:12 PM UTC+1, Nikolas Everett wrote:
> >>
> >> So I went and created a somewhat reusable component and published it in
> >> npm.  It really isn't worth anyone's time at this point but it I've
> >> encountered an issue.  My problem is that I want to log stuff in my
> module
> >> so I went and included winston and logged to my little heart's content
> and
> >> it works great in the cli application but when I embed my module I can
> no
> >> longer control the log level.  I suppose this has something to do with
> >> require's scoping to prevent library hell.  What is the standard way to
> >> configure logging in libraries?
> >
> > --
> > 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 nodejs@googlegroups.com
> > To unsubscribe from this group, send email to
> > nodejs+unsubscr...@googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/group/nodejs?hl=en?hl=en
>
> --
> 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 nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>

-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to