4front-logger 中文文档教程
4front-logger
4front 多租户网络应用程序平台的默认记录器。 了解更多信息:4front.io
内部 bunyan 用于 JSON 日志记录。 根据 12 因素应用实践,默认情况下错误和警告会流式传输到 process.stderr
和信息级别消息流式传输到 process.stdout
。 可以通过如下所述的选项覆盖此行为。 推荐的做法是在节点应用程序外部设置一个日志接收器,它将日志事件从集群中的所有服务器发送到集中式日志记录系统,例如 Splunk,Loggly,或 Papertrail。
Installation
npm install 4front-logger
Usage
var app = express();
var log = require('4front-logger')({
loggerName: "4front-logger"
});
// Register the logger with 4front
app.settings.logger = log;
Options
loggerName
将由
errStream
添加的记录器的名称 写入错误级别消息的流。 默认为 process.stderr
。
警告流
写入警告级别消息的流。 默认为 process.stderr
。
信息流
写入信息级消息的流。 默认为 process.stdout
。
ignoreErrorStatus
要忽略的 http err.status
代码数组。 默认为 [404]
。
API
error
、warn
或 info
中的任何方法都可以用 bunyan 支持:
log.info("informational message");
log.info({foo: 'bar'}, 'hi');
此外,error
函数包括一个特殊的重载,它接受一个 Error 对象和一个 Express req< /代码> 对象。 记录器将确保在日志条目中捕获所有错误详细信息以及在
req
上找到的其他上下文信息。 4front 在错误处理中间件中使用此方法:
app.use(function(err, req, res, next) {
log.error(err, req);
next();
});
Running Tests
npm test
License
在 Apache 许可下获得许可,版本 2.0。 请参阅顶级文件 LICENSE.txt 和 (http://www.apache.org/licenses/LICENSE-2.0)。
4front-logger
Default logger for the 4front multi-tenant web app platform. Learn more at: 4front.io
Internally bunyan is used for JSON logging. In accordance with 12 factor app practices, by default errors and warnings are are streamed to process.stderr
and info level messages are streamed to process.stdout
. This behavior can be overridden via the options as described below. Recommended practice is to setup a log sink external to the node app which sends log events from all servers in a cluster to a centralized logging system such as Splunk, Loggly, or Papertrail.
Installation
npm install 4front-logger
Usage
var app = express();
var log = require('4front-logger')({
loggerName: "4front-logger"
});
// Register the logger with 4front
app.settings.logger = log;
Options
loggerName
The name of the logger which will be added by
errStream
The stream where error level messages are written. Defaults to process.stderr
.
warnStream
The stream where warn level messages are written. Defaults to process.stderr
.
infoStream
The stream where info level messages are written. Defaults to process.stdout
.
ignoreErrorStatus
Array of http err.status
codes to ignore. Defaults to [404]
.
API
Any of the methods error
, warn
, or info
can be called in all the ways that bunyan supports:
log.info("informational message");
log.info({foo: 'bar'}, 'hi');
Additionally the error
function includes a special overload that accepts an Error object and an Express req
object. The logger will ensure that all the error detail along with additional contextual information found on the req
are captured in the log entry. 4front uses this method in error handling middleware:
app.use(function(err, req, res, next) {
log.error(err, req);
next();
});
Running Tests
npm test
License
Licensed under the Apache License, Version 2.0. See the top-level file LICENSE.txt and (http://www.apache.org/licenses/LICENSE-2.0).