feature: 1)启用日志压缩;2)日志保留数和保存路径可配置化。 (#432)

pull/434/head
王良 2025-01-10 13:49:34 +08:00 committed by GitHub
parent cb7a3c6e7f
commit 3a53756e23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 7 deletions

View File

@ -69,6 +69,10 @@ module.exports = {
// 慢速IP延迟时间测速超过该值时则视为延迟高显示为橙色
lowSpeedDelay: 200,
// 日志相关配置
logFileSavePath: path.join(getUserBasePath(), '/logs'), // 日志文件保存路径
keepLogFileCount: 15, // 保留日志文件数
},
compatible: {
// **** 自定义兼容配置 **** //

View File

@ -1,4 +1,5 @@
const log4js = require('./util.logger')
const logger = log4js.getLogger('core')
module.exports = logger

View File

@ -5,19 +5,44 @@ const config = require('../config/index')
const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info'
function getDefaultConfigBasePath () {
return config.server.setting.userBasePath
if (config.server.setting.logFileSavePath) {
let logFileSavePath = config.server.setting.logFileSavePath
if (logFileSavePath.endsWith('/') || logFileSavePath.endsWith('\\')) {
logFileSavePath = logFileSavePath.slice(0, -1)
}
// eslint-disable-next-line no-template-curly-in-string
return logFileSavePath.replace('${userBasePath}', config.server.setting.userBasePath)
} else {
return path.join(config.server.setting.userBasePath, '/logs')
}
}
const coreLogFilename = path.join(getDefaultConfigBasePath(), '/logs/core.log')
const guiLogFilename = path.join(getDefaultConfigBasePath(), '/logs/gui.log')
const serverLogFilename = path.join(getDefaultConfigBasePath(), '/logs/server.log')
// 日志文件名
const coreLogFilename = path.join(getDefaultConfigBasePath(), '/core.log')
const guiLogFilename = path.join(getDefaultConfigBasePath(), '/gui.log')
const serverLogFilename = path.join(getDefaultConfigBasePath(), '/server.log')
// 日志相关配置
const backups = config.server.setting.keepLogFileCount // 保留日志文件数
const appenderConfig = {
type: 'file',
pattern: 'yyyy-MM-dd',
keepFileExt: true, // 保留日志文件扩展名
compress: true, // 压缩日志文件
// 以下三个配置都设置,兼容新旧版本
backups,
numBackups: backups,
daysToKeep: backups,
}
// 设置日志配置
log4js.configure({
appenders: {
std: { type: 'stdout' },
core: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: coreLogFilename },
gui: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: guiLogFilename },
server: { level: 'debug', type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename: serverLogFilename },
core: { ...appenderConfig, filename: coreLogFilename },
gui: { ...appenderConfig, filename: guiLogFilename },
server: { ...appenderConfig, filename: serverLogFilename },
},
categories: {
default: { appenders: ['std'], level },

View File

@ -450,6 +450,13 @@ export default {
预发布版本号为带有 <code>-</code> 的版本该配置只对当前版本为正式版本时有效
</div>
</a-form-item>
<hr>
<a-form-item label="日志文件保存路径" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-input v-model="config.server.setting.logFileSavePath" />
</a-form-item>
<a-form-item label="保留日志文件数" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-input-number v-model="config.server.setting.keepLogFileCount" :step="1" :min="0" />
</a-form-item>
</div>
<template slot="footer">
<div class="footer-bar">