bug fix:fix read log file oom

This commit is contained in:
hantmac
2019-09-01 00:06:26 +08:00
parent 444784d5b6
commit 7c0c490f1c

View File

@@ -34,9 +34,16 @@ func GetLocalLog(logPath string) (fileBytes []byte, err error) {
return nil, err
}
defer f.Close()
logBuf := make([]byte, 2048)
n, err := f.ReadAt(logBuf, fi.Size()-int64(len(logBuf)))
if err != nil {
const bufLen = 2048
logBuf := make([]byte, bufLen)
off := int64(0)
if fi.Size() > int64(len(logBuf)) {
off = fi.Size() - int64(len(logBuf))
}
n, err := f.ReadAt(logBuf, off)
//到文件结尾会有EOF标识
if err != nil && err.Error() != "EOF" {
log.Error(err.Error())
debug.PrintStack()
return nil, err