mirror of
https://github.com/daeuniverse/dae.git
synced 2025-02-22 12:38:34 +07:00
feat: support to set log level in config file
This commit is contained in:
parent
e2ecb80c26
commit
e097acaa8e
21
cmd/run.go
21
cmd/run.go
@ -25,9 +25,16 @@ var (
|
||||
if cfgFile == "" {
|
||||
logrus.Fatalln("Argument \"--config\" or \"-c\" is required but not provided.")
|
||||
}
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
log := logger.NewLogger(2, disableTimestamp)
|
||||
if err := Run(log); err != nil {
|
||||
|
||||
// Read config from --config cfgFile.
|
||||
param, err := readConfig(cfgFile)
|
||||
if err != nil {
|
||||
logrus.Fatalln("readConfig: %w", err)
|
||||
}
|
||||
|
||||
log := logger.NewLogger(param.Global.LogLevel, disableTimestamp)
|
||||
logrus.SetLevel(log.Level)
|
||||
if err := Run(log, param); err != nil {
|
||||
logrus.Fatalln(err)
|
||||
}
|
||||
},
|
||||
@ -39,17 +46,11 @@ func init() {
|
||||
runCmd.PersistentFlags().BoolVarP(&disableTimestamp, "disable-timestamp", "", false, "disable timestamp")
|
||||
}
|
||||
|
||||
func Run(log *logrus.Logger) (err error) {
|
||||
func Run(log *logrus.Logger, param *config.Params) (err error) {
|
||||
|
||||
// Require "sudo" if necessary.
|
||||
internal.AutoSu()
|
||||
|
||||
// Read config from --config cfgFile.
|
||||
param, err := readConfig(cfgFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("readConfig: %w", err)
|
||||
}
|
||||
|
||||
// Resolve subscriptions to nodes.
|
||||
nodeList := make([]string, len(param.Node))
|
||||
copy(nodeList, param.Node)
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
|
||||
type Global struct {
|
||||
TproxyPort uint16 `mapstructure:"tproxy_port" default:"12345"`
|
||||
LogLevel string `mapstructure:"log_level" default:"info"`
|
||||
CheckUrl string `mapstructure:"check_url" default:"https://connectivitycheck.gstatic.com/generate_204"`
|
||||
CheckInterval time.Duration `mapstructure:"check_interval" default:"15s"`
|
||||
DnsUpstream string `mapstructure:"dns_upstream" default:"1.1.1.1:53"`
|
||||
|
@ -2,6 +2,9 @@ global {
|
||||
# tproxy port to listen.
|
||||
tproxy_port: 12345
|
||||
|
||||
# Log level: error, warn, info, debug, trace
|
||||
log_level: info
|
||||
|
||||
# Node connectivity check.
|
||||
check_url: 'https://connectivitycheck.gstatic.com/generate_204'
|
||||
check_interval: 30s
|
||||
@ -63,7 +66,7 @@ group {
|
||||
|
||||
# See routing.md for full examples.
|
||||
routing {
|
||||
ip(geoip:private, 240.0.0.0/4, 'ff00::/8') -> direct # Put me at the first place. Or you know what you're doing.
|
||||
ip(geoip:private, 224.0.0.0/3, 'ff00::/8') -> direct # Put it first unless you know what you're doing.
|
||||
# Write your rules below.
|
||||
|
||||
# dae arms DNS rush-answer filter so we can use 8.8.8.8 regardless of DNS pollution.
|
||||
|
@ -10,19 +10,12 @@ import (
|
||||
prefixed "github.com/x-cray/logrus-prefixed-formatter"
|
||||
)
|
||||
|
||||
func NewLogger(verbose int, disableTimestamp bool) *logrus.Logger {
|
||||
func NewLogger(logLevel string, disableTimestamp bool) *logrus.Logger {
|
||||
log := logrus.New()
|
||||
|
||||
var level logrus.Level
|
||||
switch verbose {
|
||||
case 0:
|
||||
level = logrus.WarnLevel
|
||||
case 1:
|
||||
level, err := logrus.ParseLevel(logLevel)
|
||||
if err != nil {
|
||||
level = logrus.InfoLevel
|
||||
case 2:
|
||||
level = logrus.DebugLevel
|
||||
default:
|
||||
level = logrus.TraceLevel
|
||||
}
|
||||
|
||||
log.SetLevel(level)
|
||||
|
Loading…
Reference in New Issue
Block a user