loading words...

Feb 12, 2019 23:51:57


by @swizecteller | 204 words | 🐣 | 116💌

Swizec Teller

Current day streak: 0🐣
Total posts: 116💌
Total words: 32303 (129 pages 📄)

Yesterday I learned about winston – a logging library for node. #200wordsTIL

I don't know why Winston is called Winston it's not a very obvious name for a console.log alternative and that's the cool thing about livecoding: People tell you stuff.


So winston is a logger for node.

What's a logger you might ask? A logger is a "service" that lets you collect logs from your code and send them to an output.



In this case a logger is a JavaScript object that takes messages and dumps them to stdout where CloudWatch (because I'm on AWS Lambda) collects them and puts them in a stream.


The benefit of Winston over console.log is that:

1) You get prettier output. JSON highlights etc.

2) You get log levels. logger.debug, logger.info, things like that.


Log levels are great when you want to jump between dev and prod modes.


However Winston also has a funny side-effect. It expects to always get a message and an object.

So if you call logger.debug("my string looks like", string)

You are made painfully aware that strings are arrays also.


So that was fun. Winston is cool. Consider giving him a shot next time you write a lot of console logs.

contact: email - twitter / Terms / Privacy