log rotete 수정

main
JungJun 2 years ago
parent 5f5bf6d56d
commit 9bd7c5c962

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"math" "math"
"os" "os"
"path/filepath"
"sync" "sync"
"time" "time"
@ -203,8 +204,38 @@ func (s IcsService) LogWatcher() *icserror.IcsError {
// /logs/voiceGW/tlo/{YYYYMMDD}/LGT.001.202207140313.log // /logs/voiceGW/tlo/{YYYYMMDD}/LGT.001.202207140313.log
// s.log.Path: /logs/voiceGW/tlo 로 변경 // s.log.Path: /logs/voiceGW/tlo 로 변경
// 일자별 rotate를 날짜 폴더로 이동 // 일자별 rotate를 날짜 폴더로 이동
s.log.LogFileName = fmt.Sprintf("%s/%d%02d%02d/LGT.%03d.%d%02d%02d%02d%02d.log", s.log.Path, y2, m2, d2, s.config.InfoConfig.ServerID, y2, m2, d2, h2, mi2) s.log.LogFileName = fmt.Sprintf("%s/%d%02d%02d/LGT.%03d.%d%02d%02d%02d%02d.log", s.log.Path, y2, m2, d2, s.config.InfoConfig.ServerID, y2, m2, d2, h2, mi2)
_, err := os.Stat(s.log.LogFileName)
if err == nil {
var oerr error
oerr = os.MkdirAll(filepath.Dir(s.log.LogFileName), 0777)
if oerr != nil {
icserror.ICSERRMakeDir.SetError(oerr)
icserror.ICSERRMakeDir.PrintWithCaller(0)
return icserror.ICSERRMakeDir
}
s.log.LogFile, oerr = os.OpenFile(s.log.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
if oerr != nil {
icserror.ICSERRFileOpen.SetError(oerr)
//icserror.ICSERRFileOpen.PrintWithCaller(1)
s.log.M.Unlock()
return icserror.ICSERRFileOpen
}
} else {
var oerr error var oerr error
oerr = os.MkdirAll(filepath.Dir(s.log.LogFileName), 0777)
if oerr != nil {
fmt.Println("mkdir err : ", oerr)
icserror.ICSERRMakeDir.SetError(oerr)
icserror.ICSERRMakeDir.PrintWithCaller(0)
return icserror.ICSERRMakeDir
}
fmt.Println("mkdir success")
s.log.LogFile, oerr = os.OpenFile(s.log.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777) s.log.LogFile, oerr = os.OpenFile(s.log.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
if oerr != nil { if oerr != nil {
icserror.ICSERRFileOpen.SetError(oerr) icserror.ICSERRFileOpen.SetError(oerr)
@ -213,6 +244,18 @@ func (s IcsService) LogWatcher() *icserror.IcsError {
s.log.M.Unlock() s.log.M.Unlock()
return icserror.ICSERRFileOpen return icserror.ICSERRFileOpen
} }
}
// s.log.LogFileName = fmt.Sprintf("%s/%d%02d%02d/LGT.%03d.%d%02d%02d%02d%02d.log", s.log.Path, y2, m2, d2, s.config.InfoConfig.ServerID, y2, m2, d2, h2, mi2)
// var oerr error
// s.log.LogFile, oerr = os.OpenFile(s.log.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
// if oerr != nil {
// icserror.ICSERRFileOpen.SetError(oerr)
// //icserror.ICSERRFileOpen.PrintWithCaller(1)
// s.log.M.Unlock()
// return icserror.ICSERRFileOpen
// }
s.log.M.Unlock() s.log.M.Unlock()
// l.Printf(icslog.LOG_LEVEL_INFO, -1, "Log Watcher: Updated Log File - %s", s.log.LogFileName) // l.Printf(icslog.LOG_LEVEL_INFO, -1, "Log Watcher: Updated Log File - %s", s.log.LogFileName)

Loading…
Cancel
Save