eggjs日志配置
## //config.default.js
// 日志配置config.logger = {level: "INFO", // SILENT, DEBUG, INFO, WARN, ERROR, FATALconsoleLevel: "DEBUG", // 控制台日志输出级别dir: "/logs", // 日志文件的存储目录type: "dateFile", // 表示按日期记录日志 console: true, // 是否在控制台输出日志disableConsoleAfterReady: false, // 当应用 ready 之后,是否禁用控制台输出。// 其他日志配置项...};
## 如何记录自己的日志 测试
class HomeController extends Controller {async index() {// 记录一条 debug 信息this.logger.debug('这是一条 debug 信息');// 记录一条 info 信息this.logger.info('这是一条 info 信息');// 记录一条 warn 信息this.logger.warn('这是一条 warn 信息');// 记录一条 error 信息this.logger.error('这是一条 error 信息');ctx.body = 'hi, egg';}
}// 均会在控制台打印// 其中 error 会被写入本地日志 common-error.log 和 init-web.log中 // 除了debug 信息外 都会写入 init-web.log
## 日志文件介绍
业务日志
common-error.log /// this.logger.error('这是一条 error 信息'); 会记录在这
egg-agent.log
egg-web.log
定时任务日志
egg-schedule.log
## 第三步对框架启动日志,需要在启动命令上加参数