|
@@ -2,17 +2,19 @@ package utils
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
"github.com/beego/beego/v2/core/logs"
|
|
|
"github.com/sirupsen/logrus"
|
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
|
"os"
|
|
|
"path"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- DefaultLogPath = "./rdlucklog"
|
|
|
- DefaultBinlogPath = "./binlog"
|
|
|
- DefaultBinlogFile = "binlog.log"
|
|
|
+ DefaultLogPath = "./etalogs/filelog"
|
|
|
+ DefaultBinlogPath = "./etalogs/binlog"
|
|
|
+ DefaultApiLogPath = "./etalogs/apilog"
|
|
|
)
|
|
|
|
|
|
var FileLog = logrus.New()
|
|
@@ -26,14 +28,16 @@ func init() {
|
|
|
}
|
|
|
logFile := LogFile
|
|
|
if logFile == "" {
|
|
|
- logFile = APP_NAME_EN + ".log"
|
|
|
+ logFile = fmt.Sprintf("%s.log", time.Now().Format(FormatDateUnSpace))
|
|
|
}
|
|
|
os.MkdirAll(logPath, os.ModePerm)
|
|
|
|
|
|
|
|
|
logFileName := path.Join(logPath, logFile)
|
|
|
+ logConf := getDefaultLogrusConfig(logFileName)
|
|
|
+ logConf.MaxAge = 1
|
|
|
|
|
|
- rolling(FileLog, logFileName)
|
|
|
+ rolling(FileLog, logConf)
|
|
|
|
|
|
|
|
|
jsonFormat := new(logrus.JSONFormatter)
|
|
@@ -45,6 +49,7 @@ func init() {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
initBinlog()
|
|
|
initApiLog()
|
|
@@ -71,7 +76,7 @@ func initBinlog() {
|
|
|
}
|
|
|
binlogFile := BinLogFile
|
|
|
if binlogFile == "" {
|
|
|
- binlogFile = DefaultBinlogFile
|
|
|
+ binlogFile = fmt.Sprintf("%s.log", time.Now().Format(FormatDateUnSpace))
|
|
|
}
|
|
|
os.MkdirAll(binlogPath, os.ModePerm)
|
|
|
logFileName := path.Join(binlogPath, binlogFile)
|
|
@@ -89,22 +94,19 @@ func initBinlog() {
|
|
|
func initApiLog() {
|
|
|
logPath := ApiLogPath
|
|
|
if logPath == "" {
|
|
|
- if RunMode == "release" {
|
|
|
- logPath = `/data/etalogs/` + APP_NAME_EN
|
|
|
- } else {
|
|
|
- logPath = `./rdlucklog/api`
|
|
|
- }
|
|
|
+ logPath = DefaultApiLogPath
|
|
|
}
|
|
|
logFile := ApiLogFile
|
|
|
if logFile == "" {
|
|
|
- logFile = APP_NAME_EN + "_api.log"
|
|
|
+ logFile = fmt.Sprintf("%s.log", time.Now().Format(FormatDateUnSpace))
|
|
|
}
|
|
|
os.MkdirAll(logPath, os.ModePerm)
|
|
|
|
|
|
|
|
|
logFileName := path.Join(logPath, logFile)
|
|
|
+ logConf := getDefaultLogrusConfig(logFileName)
|
|
|
|
|
|
- rolling(ApiLog, logFileName)
|
|
|
+ rolling(ApiLog, logConf)
|
|
|
|
|
|
|
|
|
jsonFormat := new(logrus.JSONFormatter)
|
|
@@ -114,16 +116,21 @@ func initApiLog() {
|
|
|
}
|
|
|
|
|
|
|
|
|
-func rolling(fLog *logrus.Logger, logFile string) {
|
|
|
+func rolling(fLog *logrus.Logger, config *lumberjack.Logger) {
|
|
|
|
|
|
- fLog.SetOutput(&lumberjack.Logger{
|
|
|
+ fLog.SetOutput(config)
|
|
|
+}
|
|
|
+
|
|
|
+func getDefaultLogrusConfig(logFile string) (config *lumberjack.Logger) {
|
|
|
+ config = &lumberjack.Logger{
|
|
|
Filename: logFile,
|
|
|
- MaxSize: 100,
|
|
|
+ MaxSize: 256,
|
|
|
MaxBackups: 3,
|
|
|
MaxAge: 7,
|
|
|
Compress: true,
|
|
|
LocalTime: true,
|
|
|
- })
|
|
|
+ }
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
func getDefaultLogConfig() logConfig {
|