FIX 当日志文件小于2048的时候无法正常拉取日志的问题
This commit is contained in:
陈景阳
2019-08-31 12:42:53 +08:00
parent 53ab5b6016
commit 57dddc84ed
2 changed files with 9 additions and 4 deletions

View File

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

View File

@@ -97,7 +97,7 @@ func GetCurrentNode() (model.Node, error) {
Key: key,
Id: bson.NewObjectId(),
Ip: ip,
Name: key,
Name: ip,
Mac: mac,
IsMaster: true,
}
@@ -205,7 +205,7 @@ func UpdateNodeStatus() {
// 数据库不存在该节点
node = model.Node{
Key: key,
Name: key,
Name: data.Ip,
Ip: data.Ip,
Port: "8000",
Mac: data.Mac,