1

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?

4

1 回答 1

2

我对 log4j 不太了解,对 Winston 也不太了解;超过3分钟没有使用它。
但以下是我希望在日志系统中看到的几个优点:

错误级别

我必须能够指定我想写入的日志级别。最好也有一些默认值(警告、错误、调试等)。

流媒体

当某些内容被记录时,您可以做任何您想做的事情:将其写入文件、将其写入数据库等。这取决于您。

定制

我希望能够:

  • 带时间戳的消息
  • 写信时的彩色消息process.stdout(在开发过程中非常重要!)
  • 可以使用级别(用于文件)或其他任何内容(在同一进程中启动各种记录器时)为消息添加前缀。这对于区分写入同一流的各种级别/记录器实例很有用。
于 2013-07-15T20:28:13.210 回答