mirror of
https://github.com/jkstack/libagent.git
synced 2025-12-24 12:11:57 +08:00
增加配置文件中日志文件路径转换为绝对路径的逻辑
This commit is contained in:
20
app.go
20
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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user