mirror of
https://github.com/jkstack/libagent.git
synced 2025-12-24 12:11:57 +08:00
修改log文件为相对路径时的处理逻辑
This commit is contained in:
9
app.go
9
app.go
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
rt "runtime"
|
||||
"time"
|
||||
|
||||
@@ -112,6 +113,14 @@ func (app *app) initLogging() {
|
||||
cfg.WriteStdout = true
|
||||
}
|
||||
cfg.Dir = app.a.Configure().Log.Dir
|
||||
if !filepath.IsAbs(cfg.Dir) {
|
||||
dir, err := os.Executable()
|
||||
if err != nil {
|
||||
fmt.Printf("can not change log.dir to absolute path: %v\n", err)
|
||||
} else {
|
||||
cfg.Dir = filepath.Join(filepath.Dir(dir), cfg.Dir)
|
||||
}
|
||||
}
|
||||
cfg.Name = app.a.AgentName()
|
||||
cfg.Size = int64(app.a.Configure().Log.Size.Bytes())
|
||||
cfg.Rotate = app.a.Configure().Log.Rotate
|
||||
|
||||
Reference in New Issue
Block a user