From f6be728ab52c4442dfb8671a66cd18e518566912 Mon Sep 17 00:00:00 2001 From: lwch Date: Wed, 14 Sep 2022 16:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9log=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=BA=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app.go b/app.go index 78b8e28..e9076e4 100644 --- a/app.go +++ b/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