|
@@ -10,29 +10,32 @@ import (
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- DefaultLogPath = "./rdlucklog"
|
|
|
- DefaultBinlogPath = "./binlog"
|
|
|
- DefaultBinlogFile = "binlog.log"
|
|
|
+ DefaultLogPath = "./etalogs/filelog"
|
|
|
+ DefaultBinlogPath = "./etalogs/binlog"
|
|
|
)
|
|
|
|
|
|
var FileLog = logrus.New()
|
|
|
var Binlog *logs.BeeLogger
|
|
|
|
|
|
func init() {
|
|
|
+ if LogMaxDays == 0 {
|
|
|
+ LogMaxDays = 30
|
|
|
+ }
|
|
|
logPath := LogPath
|
|
|
if logPath == "" {
|
|
|
logPath = DefaultLogPath
|
|
|
}
|
|
|
logFile := LogFile
|
|
|
if logFile == "" {
|
|
|
- logFile = "eta_data_init.log"
|
|
|
+ logFile = "filelog.log"
|
|
|
}
|
|
|
os.MkdirAll(logPath, os.ModePerm)
|
|
|
|
|
|
// 打开文件
|
|
|
logFileName := path.Join(logPath, logFile)
|
|
|
+ logConf := getDefaultLogrusConfig(logFileName)
|
|
|
// 使用滚动压缩方式记录日志
|
|
|
- rolling(FileLog, logFileName)
|
|
|
+ rolling(FileLog, logConf)
|
|
|
//rolling(bLogFileName)
|
|
|
// 设置日志输出JSON格式
|
|
|
jsonFormat := new(logrus.JSONFormatter)
|
|
@@ -61,7 +64,6 @@ type logConfig struct {
|
|
|
}
|
|
|
|
|
|
func initBinlog() {
|
|
|
- //binlog日志
|
|
|
//binlog日志
|
|
|
binlogPath := BinLogPath
|
|
|
if binlogPath == "" {
|
|
@@ -69,7 +71,7 @@ func initBinlog() {
|
|
|
}
|
|
|
binlogFile := BinLogFile
|
|
|
if binlogFile == "" {
|
|
|
- binlogFile = DefaultBinlogFile
|
|
|
+ binlogFile = "binlog.log"
|
|
|
}
|
|
|
os.MkdirAll(binlogPath, os.ModePerm)
|
|
|
logFileName := path.Join(binlogPath, binlogFile)
|
|
@@ -85,16 +87,21 @@ func initBinlog() {
|
|
|
}
|
|
|
|
|
|
// 日志滚动设置
|
|
|
-func rolling(fLog *logrus.Logger, logFile string) {
|
|
|
+func rolling(fLog *logrus.Logger, config *lumberjack.Logger) {
|
|
|
// 设置输出
|
|
|
- fLog.SetOutput(&lumberjack.Logger{
|
|
|
- Filename: logFile, //日志文件位置
|
|
|
- MaxSize: 100, // 单文件最大容量,单位是MB
|
|
|
- MaxBackups: 3, // 最大保留过期文件个数
|
|
|
- MaxAge: 7, // 保留过期文件的最大时间间隔,单位是天
|
|
|
- Compress: true, // 是否需要压缩滚动日志, 使用的 gzip 压缩
|
|
|
+ fLog.SetOutput(config)
|
|
|
+}
|
|
|
+
|
|
|
+func getDefaultLogrusConfig(logFile string) (config *lumberjack.Logger) {
|
|
|
+ config = &lumberjack.Logger{
|
|
|
+ Filename: logFile, //日志文件位置
|
|
|
+ MaxSize: 256, // 单文件最大容量,单位是MB
|
|
|
+ MaxBackups: 0, // 最大保留过期文件个数
|
|
|
+ MaxAge: LogMaxDays, // 保留过期文件的最大时间间隔,单位是天
|
|
|
+ Compress: true, // 是否需要压缩滚动日志, 使用的 gzip 压缩
|
|
|
LocalTime: true,
|
|
|
- })
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func getDefaultLogConfig() logConfig {
|
|
@@ -103,7 +110,7 @@ func getDefaultLogConfig() logConfig {
|
|
|
MaxLines: 0,
|
|
|
MaxSize: 1 << 28,
|
|
|
Daily: true,
|
|
|
- MaxDays: 7, //我就是喜欢31天,咋滴,不喜欢你就自己改-_-!
|
|
|
+ MaxDays: LogMaxDays, //我就是喜欢31天,咋滴,不喜欢你就自己改-_-!
|
|
|
Rotate: true,
|
|
|
Level: logs.LevelTrace,
|
|
|
//Perm: "",
|