We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
npm i koa-log4 --save
import path from 'path' const logPath = path.resolve(__dirname, "../../logs/") const config = { appenders: { access: { type: 'dateFile', pattern: '-yyyy-MM-dd.log', filename: path.join(logPath, 'access.log'), }, application: { type: 'dateFile', pattern: '-yyyy-MM-dd.log', filename: path.join(logPath, 'application.log') }, out: { type: 'console', }, }, categories: { default: { appenders: [ 'out' ], level: 'info' }, access: { appenders: [ 'access' ], level: 'info' }, application: { appenders: [ 'application' ], level: 'WARN'} } } export default config // use import config from './log4-conf' log4js.configure(config)
const logger = log4js.getLogger() const applicationLogger = log4js.getLogger('application') const accessLogFunc = log4js.koaLogger(log4js.getLogger('access'))
logger表示常规的日志,在控制台输出,applicationLogger表示应用级别的日志,会输出在对应的log文件,accessLogFunc用app.use()加载,所有访问级别的日志会全部输出在对应的日志文件。
这里我们将方法统一挂载在global上,供其它地方使用。
import { logUtil } from '../utils/log4' export default (ctx, next) => { global.logUtil = logUtil next() }
日志级别主要分为以下几种
log4js-node
The text was updated successfully, but these errors were encountered:
No branches or pull requests
koa日志管理【koa-log4】
安装
使用
配置文件
暴露方法
logger表示常规的日志,在控制台输出,applicationLogger表示应用级别的日志,会输出在对应的log文件,accessLogFunc用app.use()加载,所有访问级别的日志会全部输出在对应的日志文件。
这里我们将方法统一挂载在global上,供其它地方使用。
日志级别
日志级别主要分为以下几种
参考文档
log4js-node
The text was updated successfully, but these errors were encountered: