这么多日志module,看花了眼,大家都用的哪个呀?
发布于 12 年前 作者 xuhaijinsky2008 26668 次浏览 最后一次编辑是 8 年前

https://github.com/joyent/node/wiki/modules#wiki-logs 好多日志模块,都看花了眼,大家都用哪个记录日志呢?

Logging and dumping

ain — Brain-free syslog logging Caterpillar — Caterpillar is an awesome, simple, intuitive console logger for node.js. It supports grouping of messages, filtering log levels, colors, times, modules, custom formatters and custom transports. cfdump.js — a more visually inspiring way to dump your objects to a browser flume-rpc — A flume-compatible (RPC) logging source and sink gelf-node - gelf-node is a full implementation for sending messages in GELF (Graylog Extended Log Format) from node.js to Graylog hexy.js — hex pretty printing like xxd inspect — hierarchical object inspection displaying ancestry, properties, methods, and accessors in great detail. jog — JSON-based logger with multiple stores, namespacing, CLI and more log.js — light-weight logger that works with any writable stream, also supports a streaming parser for reading the log files generated log4js-node — a port of log4js framework for node.js logging — Super sexy color console logging. logly — A minimal logging utility to support verbose and debug modes with basic colors logule — A sexy portable logging utility using colors nlogger — Logging lib that can print also module names and line numbers, optionally in color node-logentries — A winston-compatible wrapper library for the logentries.com service node-logging — Simple colorized logging for Node.js with request logger Express middleware node-streamlogger — Extensively customizable logging, with support for rotation node-tick — v8.log processor NodeLog — Logging library for Node.js based on the java.util.logging library. nogg — Simple file/stdio logging for node.js spruce — configurable node.js logging module tracer — A powerful and customizable logging library for node.js. support color console with timestamp, line number, method name, file name and call stack. you can set transport to file, stream, database(ex: mongodb and clouddb, simpledb). keywords: log, logger, trace underscore.logger — Cross-browser and Node.js empowered logging that can be used as an Underscore mixin. Windows Event Log Js — native Node.js module to log messages to the Microsoft Windows EventLog Winston — A multi-transport async logging library for node.js PuperGrep - Real-time web view for your logs with hightlighting, grep and more.

11 回复

这种问题不用再问了,呵呵。在网站上方的搜索框里面输入“log”一搜,好多前辈有答案啦。

我比较了下tracer和bunyan,bunyan虽然理念不错,但是考虑到易用性和一些特性功能在实际生产上会用到的频率,决定在项目里面先使用tracer,功能还是挺强大的。

http://cnodejs.org/topic/4f50628498766f5a61082c93 https://github.com/baryon/tracer https://github.com/trentm/node-bunyan

這個問題一直糾結,至今沒有答案

感觉都不行,就没个像样的log吗?winston这种居然还这么多人关注

安装 Grunt 的时候也在想… 这么多模块, 作者自己都认得吗… 而且 Node 模块特分散, 到底怎么去找才好… 太多太多了

我一般先到这个网站看看

https://nodejsmodules.org/

把这么老的帖子翻出来会不会惹人烦呢?

作为Node的新人,看到的Node模块中没有一个公共的log库,而且大多数module都是采用console进行错误输出,奇怪生产系统中如果没有文件日志会是怎样?在模块列表中看到了nodejs-log4js(貌似应用不多),看到了Winston(简单实用,Nodejitsu用了这个模块),然后就翻到了这个帖子,将log的目标锁定在tracer和bunyan。

tracer:输出到文件、定义输出格式(format)、滚动日志文件、日志级别 bunyan:除了普通的日志功能外,几个特点:JSON格式、Child(跟踪日志调用栈)、DTrace(动态调整日志级别)。Joyent在产品实践系列debug部分提到这个模块,当时没有仔细看,重新翻出来看看,果然强悍!

个人开发tacer足够了,生产环境(尤其是分布式系统)中bunyan的特性更加吸引人。

我是tracer的作者,谈一点我的观点。 对于node.js,没有太好的debug工具,所以打log是必备的选项,tracer基本是为了完成这个任务来做的。简单快速,容易定制是基本设计思路。在开发阶段容易debug。 换到生产环境时,可以容易地通过设置level来限制log的输出。

为了完成这个工作,不应该搞的太复杂,我在做tracer的时候,一开始根本就不想写输出到文件的功能,因为根本就没有必要。后来虽然也写了一个输出log到文件的功能,但是我基本没有用过。那么日志输出怎么处理呢?

这个工作不应该交给app来做,应该由外部控制。原因是node.js的app非常容易崩溃,崩溃时的log是难以捕捉的。反倒是能捕捉到的出错信息都是可以预料的。可以预料的log,真的有那么多人看吗?

我在生产环境中使用forever来做app的监控,崩溃重启。将app的所有log就输出到console,由forever来将log定向到文件。

在debian linux下,我使用下面的命令来启动app

/usr/local/bin/forever start
-p /var/run/forever
–pidfile /var/run/your.app.pid
-l /root/log/your.app_$(date +%y%m%d).log -a
/usr/local/bin/nodemon --exitcrash --watch /root/app/your.app -e js,css,html /root/app/your.app/app.js --port 3001

log会按照年月日分类输出。

NodeJs很好调试啊,直接命令行,我就喜欢这样简单粗暴

@damngoto 今天去npm搞了好几个,想不通一个log Winston搞得这么复杂……

回到顶部