egg-logfile
插件说明
在某些情况下,应用服务器上某些功能需要记录单独的文件日志。本插件基于egg-logger实现,通过简单的配置即可实现记录文件日志。默认只需要配置日志文件名。
Install
$ npm i egg-logfile --save
Usage
// {app_root}/config/plugin.jsexportslogfile = enable: true package: 'egg-logfile';
Configuration
// {app_root}/config/config.default.js/** * egg-logfile default config * @member Config#logfile * @property * @property {String/Boolean} dateTime - 日志中每行记录前面增加时间的格式,false表示不自动记录时间 * @property */exportslogfile = singleFolder: true dateTime: 'YYYY-MM-DD HH:mm:ss,SSS' logs: ;
see config/config.default.js for more detail.
Example
应用配置
// {app_root}/config/config.default.js exportslogfile = logs: 'login'
导出函数原型
/** * 记录文件日志 * 此函数会导出到app和ctx对象中,可以直接使用ctx.logfile或者app.logfile记录日志 * * ctx.logfile('filename', fmt, args); * app.logfile('filename', fmt, args); * * @param * @param * @param */ ;
调用
// 在需要记录日志的地方知道调用 ctx;
see test/fixtures/apps/logfile-test for more detail.
Questions & Suggestions
Please open an issue here.