support output log to file

This commit is contained in:
yuzuki999 2023-08-21 18:50:31 +08:00
parent 24423d892c
commit 22365bc1ce
2 changed files with 21 additions and 10 deletions

View File

@ -1,19 +1,17 @@
package cmd package cmd
import ( 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"
"os/signal" "os/signal"
"runtime" "runtime"
"syscall" "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 ( var (
@ -56,6 +54,16 @@ func serverHandle(_ *cobra.Command, _ []string) {
case "error": case "error":
log.SetLevel(log.ErrorLevel) 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() limiter.Init()
log.Info("Start V2bX...") log.Info("Start V2bX...")
vc, err := vCore.NewCore(c.CoresConfig) vc, err := vCore.NewCore(c.CoresConfig)

View File

@ -2,7 +2,10 @@
"Log": { "Log": {
// V2bX Core log // V2bX Core log
"Level": "error" // info, warn, error, none
"Level": "error",
//
"Output": ""
}, },
"Cores": [ "Cores": [
{ {