From 22365bc1ce057e0bebd82e16ad6f3d9ed490533c Mon Sep 17 00:00:00 2001 From: yuzuki999 Date: Mon, 21 Aug 2023 18:50:31 +0800 Subject: [PATCH] support output log to file --- cmd/server.go | 26 +++++++++++++++++--------- example/config.json | 5 ++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 6dae1cf..18d5b11 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -1,19 +1,17 @@ package cmd import ( + "github.com/InazumaV/V2bX/conf" + vCore "github.com/InazumaV/V2bX/core" + "github.com/InazumaV/V2bX/limiter" + "github.com/InazumaV/V2bX/node" + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "gopkg.in/natefinch/lumberjack.v2" "os" "os/signal" "runtime" "syscall" - - log "github.com/sirupsen/logrus" - - vCore "github.com/InazumaV/V2bX/core" - - "github.com/InazumaV/V2bX/conf" - "github.com/InazumaV/V2bX/limiter" - "github.com/InazumaV/V2bX/node" - "github.com/spf13/cobra" ) var ( @@ -56,6 +54,16 @@ func serverHandle(_ *cobra.Command, _ []string) { case "error": log.SetLevel(log.ErrorLevel) } + if c.LogConfig.Output != "" { + w := &lumberjack.Logger{ + Filename: c.LogConfig.Output, + MaxSize: 100, + MaxBackups: 3, + MaxAge: 28, + Compress: true, + } + log.SetOutput(w) + } limiter.Init() log.Info("Start V2bX...") vc, err := vCore.NewCore(c.CoresConfig) diff --git a/example/config.json b/example/config.json index 86764db..3d087f7 100644 --- a/example/config.json +++ b/example/config.json @@ -2,7 +2,10 @@ "Log": { // V2bX 的日志配置,独立于各 Core 的 log 配置 - "Level": "error" + // 日志等级,info, warn, error, none + "Level": "error", + // 日志输出路径,默认输出到标准输出 + "Output": "" }, "Cores": [ {