winston日志管理2
上次讲到
Exceptions 例外
Handling Uncaught Exceptions with winston 使用winston处理未捕获的异常(这个如果对于异步,我不是很喜欢用)
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
//
// 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')winstonallows you to define alevelproperty on each transport which specifies the maximum level of messages that a transport should log. For example, using thenpmlevels you could log onlyerrormessages to the console and everythinginfoand below to a file (which includeserrormessages): 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的更多相关文章
- winston日志管理1
Usage There are two different ways to use winston: directly via the default logger, or by instantiat ...
- winston日志管理3
Further Reading 延伸阅读 Events and Callbacks in Winston winston的事件和回调 Each instance of winston.Logger i ...
- winston 日志管理4
配置File Transport winston.add(winston.transports.File, options) The File transport should really be t ...
- Nodejs日志管理包
Nodejs日志管理工具包:log4js 和 winston 1.log4js的使用 1)package.json中加入依赖 "log4js":"~0.6.21" ...
- 第13章 Linux日志管理
1. 日志管理 (1)简介 在CentOS 6.x中日志服务己经由rsyslogd取代了原先的syslogd服务.rsyslogd日志服务更加先进,功能更多.但是不论该服务的使用,还是日志文件的格式其 ...
- ABP(现代ASP.NET样板开发框架)系列之8、ABP日志管理
点这里进入ABP系列文章总目录 基于DDD的现代ASP.NET开发框架--ABP系列之8.ABP日志管理 ABP是“ASP.NET Boilerplate Project (ASP.NET样板项目)” ...
- 【Java EE 学习 76 下】【数据采集系统第八天】【通过AOP实现日志管理】【日志管理功能分析和初步实现】
一.日志管理相关分析 1.日志管理是一种典型的系统级别的应用,非常适合使用spring AOP实现. 2.使用日志管理的目的:对系统修改的动作进行记录,比如对权限.角色.用户的写操作.修改操作.删除操 ...
- ElasticSearch+NLog+Elmah实现Asp.Net分布式日志管理
本文将介绍使用NLOG.Elmah结合ElasticSearch实现分布式日志管理. 一.ElasticSearch简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布 ...
- Apache 日志管理,获取客户端端口号
日志管理分类 日志文件是用户管理和监控 Apache 安全的非常好的第一手资料,它清晰地记录了客户端访问 Apache 服务器资源的每一条记录,以及在访问中出现的错误信息,可以这样说,Apache 可 ...
随机推荐
- 客户端显示Not yet reported
No.1: IIS, WSUS, 加域的顺序,不过貌似关系不大,按照这个顺序就行了. No.2: KB2734608, KB2720211的影响,3.2.7600.256 (KB2734608), ...
- multipart/form-data请求与文件上传
要上传文件,需要用post方法,并且设置enctype为multipart/form-data. <form action="/upload" method="po ...
- mysql通过data目录恢复数据库
mysql通过data目录恢复数据库 阅读:次 时间:2010-03-24 06:53:30 字体:[大 中 小] 重装系统后,MySQL服务没有了,但是数据库的文件还在,这个时候我想 ...
- WordPress博客教程:博客赚钱
稍有关注独立博客的人都应该知道,中文博客实现盈利非常艰难,至少对于大部分中文博客来说是这样的.但很多时候我们不得不往赚钱的方向前进,至少要交得起域名和空间的租用费吧.不过期待赚钱前,你必须思考下如何提 ...
- 20145225 实验四《Andoid开发基础》
实验内容 搭建Android环境 运行Android 修改代码,能输出学号 实验步骤 安装Android Studio 安装Android的SDK 运行Andriod Studio并在模拟手机上显示自 ...
- java--字符串替换replace,replaceAll,replaceFirst
1.字符串替换,replace string s="abcdfersabcdsgacabc"; 将字符串中的abc替换成bdf s.replace("abc", ...
- ubuntu timezone
change timezone sudo dpkg-reconfigure tzdata synchronize time sudo ntpdate time.windows.com
- js制作带有遮罩弹出层实现登录小窗口
要实现的效果如下 点击“登录”按钮后,弹出登录小窗口,并且有遮罩层(这个名词还是百度知道的,以前只知道效果,却不知道名字) 在没有点击“登录”按钮之前登录小窗口不显示,点击“登录”按钮后小窗口显示,并 ...
- 【转】Unity3D研究院之通过C#使用Advanced CSharp Messenger(五十)
http://www.xuanyusong.com/archives/2165 Advanced CSharp Messenger 属于C#事件的一种. 维基百科中由详细的说明http://wiki. ...
- java ObjectOutputStream
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...