1.0.6 • Published 3 years ago
wikibit-winston-log v1.0.6
wikibit-winston-log
这是一个 NUXT 项目的依赖于 winston 的插件
使用方法:
- 直接注入到 nuxt 项目
nuxt.config.js
文件modules
选项下 - 参数实例
{ logPath: './log' }
logPath
参数为日志路径 默认为./log
在开发环境(windows 环境下设置不生效,强制为./log
)
modules: [
['wikibit-winston-log', { logPath: './log' }],
],
日志将会默认输出在 ./logs/{NODE_ENV}.log
或者是你自定义的目录下 但是在开发环境(windows 环境下设置不生效,强制为./log
)
引用方法
- Install npm package
$ yarn add wikibit-winston-log # or npm i wikibit-winston-log
- 根据需要使用$winstonLog 键更改选项。有关详细信息,请参见示例:
if ($winstonLog) {
// $winstonLog只在服务端存在,需要判断是否存在
$winstonLog.error(
`[status:${err.status}] |errCode:${err.code}| url:${err.config.url} | message:${err.message}`
)
}
Usage
配置
// ... { // Path that log files will be created in. // Change this to keep things neat. logPath: './logs', // Name of log file. // Change this to keep things tidy. logName: `${process.env.NODE_ENV}.log`, // Setting to determine if filesystem is accessed to auto-create logPath. // Set this to `false` for non-filesystem based logging setups. autoCreateLogPath: true, // Setting to determine if default logger instance is created for you. // Set this to `false` and provide `loggerOptions` (usage item #3) to // completely customize the logger instance (formatting, transports, etc.) useDefaultLogger: true, // Settings to determine if default handlers should be // registered for requests and errors respectively. // Set to `true` to skip request logging (level: info). skipRequestMiddlewareHandler: false, // Set to `true` to skip error logging (level: error). skipErrorMiddlewareHandler: false } // ...