main
JungJun 2 years ago
parent 94643d39de
commit 63f9fc1c12

@ -145,50 +145,61 @@ func NewIcsLog(conf *icsconf.LogConfig, level int, output int, path string, disk
stat, err := os.Stat(gIcsLog.LogFileName)
if err == nil {
if gIcsLog.checkLogRotate() && stat.Size()/ONEMB >= int64(gIcsLog.logSize) {
rotateNum := gIcsLog.getTodayLogFileNum()
//fmt.Println("rotate num:", rotateNum)
if rotateNum > 0 && rotateNum < gIcsLog.rotateNum {
gIcsLog.shiftLogFiles(rotateNum)
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)
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)
if oerr != nil {
//fmt.Println(gIcsLog.LogFileName)
icserror.ICSERRFileOpen.SetError(oerr)
reterr = icserror.ICSERRFileOpen
reterr.PrintWithCaller(0)
return
}
fmt.Println("err == nil", stat)
var oerr error
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
}
// if gIcsLog.checkLogRotate() && stat.Size()/ONEMB >= int64(gIcsLog.logSize) {
// rotateNum := gIcsLog.getTodayLogFileNum()
// //fmt.Println("rotate num:", rotateNum)
// if rotateNum > 0 && rotateNum < gIcsLog.rotateNum {
// gIcsLog.shiftLogFiles(rotateNum)
// 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)
// 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)
// if oerr != nil {
// //fmt.Println(gIcsLog.LogFileName)
// icserror.ICSERRFileOpen.SetError(oerr)
// reterr = icserror.ICSERRFileOpen
// reterr.PrintWithCaller(0)
// return
// }
// }
} else {
fmt.Println("err != nil")
var oerr error
oerr = os.MkdirAll(filepath.Dir(gIcsLog.LogFileName), 0777)
if oerr != nil {

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

Loading…
Cancel
Save