diff --git a/icslog/icslog.go b/icslog/icslog.go index 5fce737..eb29f0b 100644 --- a/icslog/icslog.go +++ b/icslog/icslog.go @@ -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 { diff --git a/icslog/logoutput.go b/icslog/logoutput.go index 7e2e234..c50d581 100644 --- a/icslog/logoutput.go +++ b/icslog/logoutput.go @@ -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()) }