In dev mode, logs can be saved to a file, but in production mode, logs cannot be saved to a file
RowgerGo opened this issue · 1 comments
RowgerGo commented
version:
"electron": "^25.6.0",
"electron-log": "^5.1.2",
In dev mode, logs can be saved to files, but in production mode, logs cannot be saved to files. I know it will be disabled in production mode, but how can I enable it? Here is my configuration file
import log from 'electron-log/main';
import {remote} from 'electron'
import { join } from 'path'
log.transports.file.level = "debug"
log.transports.console.level = true
log.transports.file.maxSize = 1002430 // 最大不超过10M
log.transports.file.format = '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}]{scope} {text}' // 设置文件内容格式
let date = new Date()
date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
log.transports.file.fileName = date + '.log' // 创建文件名格式为 '时间.log' (2023-02-01.log)
// 指定日志文件夹位置
log.transports.file.resolvePath = ()=>join(__dirname, `../../logs/${date}.log`)
// 有六个日志级别error, warn, info, verbose, debug, silly。默认是silly
export default {
log(param) {
log.debug(param)
},
info(param) {
log.debug(param)
},
warn(param) {
log.warn(param)
},
error(param) {
log.error(param)
},
debug(param) {
log.debug(param)
},
verbose(param) {
log.verbose(param)
},
silly(param) {
log.silly(param)
}
}
megahertz commented
This path won't work in the prod build. You need to use a default path or specify another unrelated to your app code.
log.transports.file.resolvePath = ()=>join(__dirname,
../../logs/${date}.log)