main
JungJun 2 years ago
parent 94643d39de
commit 63f9fc1c12

@ -145,22 +145,8 @@ func NewIcsLog(conf *icsconf.LogConfig, level int, output int, path string, disk
stat, err := os.Stat(gIcsLog.LogFileName) stat, err := os.Stat(gIcsLog.LogFileName)
if err == nil { if err == nil {
if gIcsLog.checkLogRotate() && stat.Size()/ONEMB >= int64(gIcsLog.logSize) { fmt.Println("err == nil", stat)
rotateNum := gIcsLog.getTodayLogFileNum()
//fmt.Println("rotate num:", rotateNum)
if rotateNum > 0 && rotateNum < gIcsLog.rotateNum {
gIcsLog.shiftLogFiles(rotateNum)
var oerr error var oerr error
oerr = os.MkdirAll(filepath.Dir(gIcsLog.LogFileName), 0777)
if oerr != nil {
fmt.Println("mkdir err : ", oerr)
icserror.ICSERRMakeDir.SetError(oerr)
icserror.ICSERRMakeDir.PrintWithCaller(0)
return
}
fmt.Println("mkdir success")
gIcsLog.LogFile, oerr = os.OpenFile(gIcsLog.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777) gIcsLog.LogFile, oerr = os.OpenFile(gIcsLog.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
if oerr != nil { if oerr != nil {
//fmt.Println(gIcsLog.LogFileName) //fmt.Println(gIcsLog.LogFileName)
@ -169,26 +155,51 @@ func NewIcsLog(conf *icsconf.LogConfig, level int, output int, path string, disk
reterr.PrintWithCaller(0) reterr.PrintWithCaller(0)
return return
} }
} // if gIcsLog.checkLogRotate() && stat.Size()/ONEMB >= int64(gIcsLog.logSize) {
} else if stat.Size()/ONEMB < int64(gIcsLog.logSize) { // rotateNum := gIcsLog.getTodayLogFileNum()
var oerr error // //fmt.Println("rotate num:", rotateNum)
oerr = os.MkdirAll(filepath.Dir(gIcsLog.LogFileName), 0777) // if rotateNum > 0 && rotateNum < gIcsLog.rotateNum {
if oerr != nil { // gIcsLog.shiftLogFiles(rotateNum)
icserror.ICSERRMakeDir.SetError(oerr)
icserror.ICSERRMakeDir.PrintWithCaller(0) // var oerr error
return // oerr = os.MkdirAll(filepath.Dir(gIcsLog.LogFileName), 0777)
} // if oerr != nil {
// fmt.Println("mkdir err : ", oerr)
// icserror.ICSERRMakeDir.SetError(oerr)
// icserror.ICSERRMakeDir.PrintWithCaller(0)
// return
// }
// fmt.Println("mkdir success")
// gIcsLog.LogFile, oerr = os.OpenFile(gIcsLog.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
// if oerr != nil {
// //fmt.Println(gIcsLog.LogFileName)
// icserror.ICSERRFileOpen.SetError(oerr)
// reterr = icserror.ICSERRFileOpen
// reterr.PrintWithCaller(0)
// return
// }
// }
// } else if stat.Size()/ONEMB < int64(gIcsLog.logSize) {
// var oerr error
// oerr = os.MkdirAll(filepath.Dir(gIcsLog.LogFileName), 0777)
// if oerr != nil {
// icserror.ICSERRMakeDir.SetError(oerr)
// icserror.ICSERRMakeDir.PrintWithCaller(0)
// return
// }
gIcsLog.LogFile, oerr = os.OpenFile(gIcsLog.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777) // gIcsLog.LogFile, oerr = os.OpenFile(gIcsLog.LogFileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
if oerr != nil { // if oerr != nil {
//fmt.Println(gIcsLog.LogFileName) // //fmt.Println(gIcsLog.LogFileName)
icserror.ICSERRFileOpen.SetError(oerr) // icserror.ICSERRFileOpen.SetError(oerr)
reterr = icserror.ICSERRFileOpen // reterr = icserror.ICSERRFileOpen
reterr.PrintWithCaller(0) // reterr.PrintWithCaller(0)
return // return
} // }
} // }
} else { } else {
fmt.Println("err != nil")
var oerr error var oerr error
oerr = os.MkdirAll(filepath.Dir(gIcsLog.LogFileName), 0777) oerr = os.MkdirAll(filepath.Dir(gIcsLog.LogFileName), 0777)
if oerr != nil { if oerr != nil {

@ -44,6 +44,7 @@ func (l *IcsLog) Printf(level int, sessionID int, format string, a ...interface{
if err != nil { if err != nil {
msg = fmt.Sprintf("Could not get log file(%s) size", l.LogFileName) msg = fmt.Sprintf("Could not get log file(%s) size", l.LogFileName)
l.logger.Output(2, msg) l.logger.Output(2, msg)
fmt.Println(msg)
if l.LogFile != nil { if l.LogFile != nil {
l.LogFile.WriteString(l.buf.String()) l.LogFile.WriteString(l.buf.String())
} }

Loading…
Cancel
Save