上次讲到

Exceptions  例外

Handling Uncaught Exceptions with winston 使用winston处理未捕获的异常(这个如果对于异步,我不是很喜欢用)

使用winston,可以从进程捕获和记录uncaughtException事件。 有两种不同的方式通过默认的winston logger或者你自己的logger实例启用这个功能。

Logging Levels 日志级别

每个级别都有一个特定的整数优先级。 优先级越高,消息被认为越重要,并且相应的整数优先级越低。 例如,npm日志记录级别的优先级从0到5(从最高到最低):

{ error: 0, warn: 1, info: 2, verbose: 3, debug: 4, silly: 5 }

Similarly, as specified exactly in RFC5424 the syslog levels are prioritized from 0 to 7 (highest to lowest).

{ emerg: 0, alert: 1, crit: 2, error: 3, warning: 4, notice: 5, info: 6, debug: 7 }

If you do not explicitly define the levels that winston should use the npm levels above will be used.

Using Logging Levels 使用logging level

Setting the level for your logging message can be accomplished in one of two ways. You can pass a string representing the logging level to the log() method or use the level specified methods defined on every winston Logger.
设置记录消息的级别可以通过两种方式之一完成。 您可以将表示日志记录级别的字符串传递给log()方法,或者使用在每个winston Logger上定义的级别指定方法。
//
// Any logger instance
//
logger.log('silly', "127.0.0.1 - there's no place like home");
logger.log('debug', "127.0.0.1 - there's no place like home");
logger.log('verbose', "127.0.0.1 - there's no place like home");
logger.log('info', "127.0.0.1 - there's no place like home");
logger.log('warn', "127.0.0.1 - there's no place like home");
logger.log('error', "127.0.0.1 - there's no place like home");
logger.info("127.0.0.1 - there's no place like home");
logger.warn("127.0.0.1 - there's no place like home");
logger.error("127.0.0.1 - there's no place like home"); 使用logger.info的方式,或者使用logger.log('info') winston allows you to define a level property on each transport which specifies the maximum level of messages that a transport should log. For example, using the npm levels you could log only error messages to the console and everything info and below to a file (which includes error messages): winston允许您在每个传输上定义一个level属性,它指定传输应该记录的最大消息级别。 例如,使用npm级别,您可以只记录到控制台的错误消息以及下面的一切信息到文件(其中包括错误消息):
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({ level: 'error' }),
new (winston.transports.File)({
filename: 'somefile.log',
level: 'info'
})
]
});
所有大于error级别的都会在console上显示,而在info上,所有大于info级别的都会写到somefile.log

Using Custom Logging Levels  使用传统的log 级别

In addition to the predefined npm and syslog levels available in Winston, you can also choose to define your own:

除了Winston中提供的预定义的npm和syslog级别之外,您还可以选择定义自己的:
var myCustomLevels = {
levels: {
foo: 0,
bar: 1,
baz: 2,
foobar: 3
},
colors: {
foo: 'blue',
bar: 'green',
baz: 'yellow',
foobar: 'red'
}
}; var customLevelLogger = new (winston.Logger)({ levels: myCustomLevels.levels });
customLevelLogger.foobar('some foobar level-ed message');
对于winston添加颜色的设置:
winston.addColors(myCustomLevels.colors);一般会在打印的时候使用.
												

winston日志管理2的更多相关文章

  1. winston日志管理1

    Usage There are two different ways to use winston: directly via the default logger, or by instantiat ...

  2. winston日志管理3

    Further Reading 延伸阅读 Events and Callbacks in Winston winston的事件和回调 Each instance of winston.Logger i ...

  3. winston 日志管理4

    配置File Transport winston.add(winston.transports.File, options) The File transport should really be t ...

  4. Nodejs日志管理包

    Nodejs日志管理工具包:log4js 和 winston 1.log4js的使用 1)package.json中加入依赖 "log4js":"~0.6.21" ...

  5. 第13章 Linux日志管理

    1. 日志管理 (1)简介 在CentOS 6.x中日志服务己经由rsyslogd取代了原先的syslogd服务.rsyslogd日志服务更加先进,功能更多.但是不论该服务的使用,还是日志文件的格式其 ...

  6. ABP(现代ASP.NET样板开发框架)系列之8、ABP日志管理

    点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之8.ABP日志管理 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)” ...

  7. 【Java EE 学习 76 下】【数据采集系统第八天】【通过AOP实现日志管理】【日志管理功能分析和初步实现】

    一.日志管理相关分析 1.日志管理是一种典型的系统级别的应用,非常适合使用spring AOP实现. 2.使用日志管理的目的:对系统修改的动作进行记录,比如对权限.角色.用户的写操作.修改操作.删除操 ...

  8. ElasticSearch+NLog+Elmah实现Asp.Net分布式日志管理

    本文将介绍使用NLOG.Elmah结合ElasticSearch实现分布式日志管理. 一.ElasticSearch简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布 ...

  9. Apache 日志管理,获取客户端端口号

    日志管理分类 日志文件是用户管理和监控 Apache 安全的非常好的第一手资料,它清晰地记录了客户端访问 Apache 服务器资源的每一条记录,以及在访问中出现的错误信息,可以这样说,Apache 可 ...

随机推荐

  1. Linux 高级网络编程

    设置套接字函数: #include<sys/socket.h> int setsockopt(int sockfd, int level, int optname, const void* ...

  2. ArcGISDynamicMapServiceLayer 实现条件过滤

    <html>   <head>   <meta http-equiv="Content-Type" content="text/html; ...

  3. sql order by+字段,指定按照哪个字段来排序

    1.我们就可以使用 MySQL 的 ORDER BY 子句来设定你想按哪个字段哪中方式来进行排序,再返回搜索结果. 2.SELECT field1, field2,...fieldN table_na ...

  4. Alamofire数据请求

    let stringurl = "http://www.huiyunche.cn/kyleuat/banner/list" Alamofire.request(.GET,strin ...

  5. [SHELL进阶] (转)最牛B的 Linux Shell 命令 (二)

    1.用你最喜欢的编辑器来敲命令 command <CTRL-x CTRL-e> 在已经敲完的命令后按 <CTRL-x CTRL-e> ,会打开一个你指定的编辑器(比如vim,通 ...

  6. Rails--bundle exec rake db:migrate

    --新建表: def up create_table :[TABLE_NAME] do |t| t.column :[NUM], :integer t.column :[NAME], :string ...

  7. MVC validation

    <div class="editor-field"> @Html.TextBoxFor(m => m.DateField) @Html.ValidationMes ...

  8. mysql默认字符集修改

    (1) 最简单的修改方法,就是修改mysql的my.ini文件中的字符集键值,添加 [mysql] default-character-set = utf8 [mysqld] character_se ...

  9. href="#"和javasrcript:void(0)的区别

    当我们需要一个空链接时,通常有两种方法: <a href="#">这个一个空链接</a> 和 <a href="javascript:voi ...

  10. 8 个最佳 PHP 库

    PHP标准库 (SPL)的目的就是提供一组接口,让开发者在PHP5中充分利用面向对象编程.因此本文我们搜集了8个最好的,能辅助开发者简化他们的工作,为他们的开发任务服务的PHP库. 如果你喜欢本文,也 ...