按月记录日志,避免logs文件夹文件过多
This commit is contained in:
parent
d6d8a6e45f
commit
cb54278363
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
.lock
|
.lock
|
||||||
|
logs/
|
||||||
|
RawData/
|
||||||
|
|||||||
BIN
iniDataForLinux
BIN
iniDataForLinux
Binary file not shown.
BIN
iniDataForMacOs
BIN
iniDataForMacOs
Binary file not shown.
19
main.go
19
main.go
@ -113,13 +113,6 @@ func init() {
|
|||||||
log.Fatal("failed to get executable path: ", err)
|
log.Fatal("failed to get executable path: ", err)
|
||||||
}
|
}
|
||||||
executableDir = filepath.Dir(executablePath)
|
executableDir = filepath.Dir(executablePath)
|
||||||
//判断目录是否存在,不存在则创建
|
|
||||||
err = os.MkdirAll(filepath.Join(executableDir, zipPath), 0755)
|
|
||||||
err = os.MkdirAll(filepath.Join(executableDir, txtPath), 0755)
|
|
||||||
err = os.MkdirAll(filepath.Join(executableDir, logPath), 0755)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
flag.StringVar(&env, "env", "dev", "运行模式")
|
flag.StringVar(&env, "env", "dev", "运行模式")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -170,6 +163,14 @@ func init() {
|
|||||||
panic(fmt.Errorf("无效的运行模式: %s", env))
|
panic(fmt.Errorf("无效的运行模式: %s", env))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//判断目录是否存在,不存在则创建
|
||||||
|
err = os.MkdirAll(filepath.Join(executableDir, zipPath), 0755)
|
||||||
|
err = os.MkdirAll(filepath.Join(executableDir, txtPath), 0755)
|
||||||
|
err = os.MkdirAll(filepath.Join(executableDir, logPath, time.Now().Format("2006_01")), 0755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
redisClient = redis.NewClient(&redis.Options{
|
redisClient = redis.NewClient(&redis.Options{
|
||||||
Addr: redisAddress,
|
Addr: redisAddress,
|
||||||
Password: redisPassword,
|
Password: redisPassword,
|
||||||
@ -192,13 +193,13 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
applogger = logrus.New()
|
applogger = logrus.New()
|
||||||
logPath := filepath.Join(executableDir, "logs")
|
logPath := filepath.Join(executableDir, "logs", time.Now().Format("2006_01"))
|
||||||
logFileName := "sms_processing_" + time.Now().Format("2006_01_02") + ".log"
|
logFileName := "sms_processing_" + time.Now().Format("2006_01_02") + ".log"
|
||||||
logFileHook := &lumberjack.Logger{
|
logFileHook := &lumberjack.Logger{
|
||||||
Filename: filepath.Join(logPath, logFileName),
|
Filename: filepath.Join(logPath, logFileName),
|
||||||
}
|
}
|
||||||
applogger.SetOutput(logFileHook)
|
applogger.SetOutput(logFileHook)
|
||||||
|
applogger.Info("程序启动....")
|
||||||
go downloadDecompression() // 启动立即执行一次
|
go downloadDecompression() // 启动立即执行一次
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Duration(taskTime) * time.Minute) // 创建一个定时器,每隔一分钟触发一次任务函数
|
ticker := time.NewTicker(time.Duration(taskTime) * time.Minute) // 创建一个定时器,每隔一分钟触发一次任务函数
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user