From d1989baf7b63b8cb10ed807377f15905744e39e0 Mon Sep 17 00:00:00 2001 From: lwch Date: Wed, 8 Feb 2023 10:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E8=BD=AC=E6=8D=A2=E4=B8=BA=E7=BB=9D=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app.go b/app.go index e9076e4..f6a6c6c 100644 --- a/app.go +++ b/app.go @@ -47,6 +47,8 @@ func newApp(a App) *app { } func (app *app) start() { + app.rel2abs() + app.initLogging() defer logging.Flush() @@ -144,3 +146,21 @@ func (app *app) debug(ctx context.Context) { } } } + +func (app *app) rel2abs() { + exe, err := os.Executable() + if err != nil { + logging.Error("get executable file dir: %v", err) + return + } + trans := func(dir string) string { + if !filepath.IsAbs(dir) { + return filepath.Join(filepath.Dir(exe), dir) + } + return dir + } + cfg := app.a.Configure() + if len(cfg.Log.Dir) > 0 { + cfg.Log.Dir = trans(cfg.Log.Dir) + } +}