Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

What are the reasons to use a logging system/module/library?

What are the reasons to use a logging system/module/library?

Problem

I'm trying to evaluate the reasons to use a Logging system like Winston in node.js vs just writing my own logging method. It seems like logging libraries don't really offer much.

Some logging systems (like log4j) have logging hierarchies where if you log to a.b.c it logs to a.b and a as well (unless you have other complicated stop-propogation configurations). Is this kind of stuff usually overkill? What situation would you need that for?

I'm considering just writing a logging function that writes logs to a mongo database, which I'll then be able to pretty easily query and search through. Presumably a logging library can do that, but it seems like it would be just as much work to use a library for that as to Write it from scratch.

So in short: what are the benefits to using a logging system?

Problem courtesy of: B T

Solution

I don't know about log4j, and not too much about Winston; haven't used it for more than 3 minutes.
But here are the few advantages I'd like to see in a logging system:

Error levels

I must be able to specify the log level I'd like to write to. It's good to have some defaults also (warning, error, debug, etc).

Streaming

You are able to do everything you want when something gets logged: Write it to a file, write it to the database, etc. It's up to you.

Customization

I'd like to be able to:

  • Timestamped messages
  • Colored messages when writing to process.stdout (super important while developing!)
  • Possibility of prefixing the message with the level (for files), or with anything else (when launching various loggers within the same process). This is useful for differentiating between various levels/logger instances that write to the same stream.
Solution courtesy of: gustavohenke

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

What are the reasons to use a logging system/module/library?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×