看到Sails的日志就会想起来log4net,确实它们在很多地方是相似的,都是采用分级别记录的方式,而sails我觉得在使用上更加方便,它不需要我们做多于的事情,直接sails.log.级别("你的日志内容")就搞定了,你不需要关心什么单例,或者持久化方式,Sails的日志只是对console.log的一种补充,可以理解为分了类之后的console.log,并有颜色的区分,呵呵。
一 我们来看一下sails.log的日志级别
Priority | level | Log fns visible |
---|---|---|
0 | silent | N/A |
1 | error | .error() |
2 | warn |
.warn() , .error()
|
3 | debug |
.debug() , .warn() , .error()
|
4 | info |
.info() , .debug() , .warn() , .error()
|
5 | verbose |
.verbose() , .info() , .debug() , .warn() , .error()
|
6 | silly |
.silly() , .verbose() , .info() , .debug() , .warn() , .error()
|
二 开始测试我们的日志
sails.log('debug日志!');//sails.log.debug("debug")
sails.log.error('error日志!');
sails.log.warn('warn日志!','request aborted.');
sails.log.info('info日志!');
sails.log.verbose('verbose日志!');
sails.log.silly('silly日志!');
三 配置项目的日志级别,位于config/log.js
module.exports.log = {
level: 'info'
};
四 从结果中看到,日志记录时,只记录比当前配置级别低的日志内容
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQQAAAB2CAIAAACh93ojAAAKbElEQVR4nO2dO5brKhaGmVUzhJ7BHYGZRdeZAZmznoHSQ+685ezKwdVqZxVcr9UOndIBWxLijUpyleX/WxXIlHjzw0bWNkwDALTWWrPvLgAAPwWIAQACYgCAgBgAICAGAIj3EgNj71VfUMVrDw4WJ3Z/OqnNSgpegNfu/uygT6jFGf27E4MSjDEm1Gtn8VReu/trV4BXXhmUqB52C6LURlycxU9ki+5X11bcN0jX543E0Ev+NDFU5LVHMVxb/vlQ15Zd7/rxKc1Qfnzy85mdz+x611qra8vaVtwfsmtZ24r/DSHXK2srRr8SjMteCcaE0r2Upil7yc1wFEpP6y+Fit9DiBCzdbnc/snuKyrF4JaQikQfueznNzLO+VQL5RgYXiyKNIWNAamRN29DE8u0mBVtllewFqG8ovXKFOm1oO6/X9n1rq4t6zreXk3txgnevmBtJx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