mirror of
https://github.com/daeuniverse/dae.git
synced 2025-07-06 00:09:37 +07:00
feat: support to set log level in config file
This commit is contained in:
21
cmd/run.go
21
cmd/run.go
@ -25,9 +25,16 @@ var (
|
|||||||
if cfgFile == "" {
|
if cfgFile == "" {
|
||||||
logrus.Fatalln("Argument \"--config\" or \"-c\" is required but not provided.")
|
logrus.Fatalln("Argument \"--config\" or \"-c\" is required but not provided.")
|
||||||
}
|
}
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
|
||||||
log := logger.NewLogger(2, disableTimestamp)
|
// Read config from --config cfgFile.
|
||||||
if err := Run(log); err != nil {
|
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)
|
logrus.Fatalln(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -39,17 +46,11 @@ func init() {
|
|||||||
runCmd.PersistentFlags().BoolVarP(&disableTimestamp, "disable-timestamp", "", false, "disable timestamp")
|
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.
|
// Require "sudo" if necessary.
|
||||||
internal.AutoSu()
|
internal.AutoSu()
|
||||||
|
|
||||||
// Read config from --config cfgFile.
|
|
||||||
param, err := readConfig(cfgFile)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("readConfig: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve subscriptions to nodes.
|
// Resolve subscriptions to nodes.
|
||||||
nodeList := make([]string, len(param.Node))
|
nodeList := make([]string, len(param.Node))
|
||||||
copy(nodeList, param.Node)
|
copy(nodeList, param.Node)
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
type Global struct {
|
type Global struct {
|
||||||
TproxyPort uint16 `mapstructure:"tproxy_port" default:"12345"`
|
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"`
|
CheckUrl string `mapstructure:"check_url" default:"https://connectivitycheck.gstatic.com/generate_204"`
|
||||||
CheckInterval time.Duration `mapstructure:"check_interval" default:"15s"`
|
CheckInterval time.Duration `mapstructure:"check_interval" default:"15s"`
|
||||||
DnsUpstream string `mapstructure:"dns_upstream" default:"1.1.1.1:53"`
|
DnsUpstream string `mapstructure:"dns_upstream" default:"1.1.1.1:53"`
|
||||||
|
@ -2,6 +2,9 @@ global {
|
|||||||
# tproxy port to listen.
|
# tproxy port to listen.
|
||||||
tproxy_port: 12345
|
tproxy_port: 12345
|
||||||
|
|
||||||
|
# Log level: error, warn, info, debug, trace
|
||||||
|
log_level: info
|
||||||
|
|
||||||
# Node connectivity check.
|
# Node connectivity check.
|
||||||
check_url: 'https://connectivitycheck.gstatic.com/generate_204'
|
check_url: 'https://connectivitycheck.gstatic.com/generate_204'
|
||||||
check_interval: 30s
|
check_interval: 30s
|
||||||
@ -63,7 +66,7 @@ group {
|
|||||||
|
|
||||||
# See routing.md for full examples.
|
# See routing.md for full examples.
|
||||||
routing {
|
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.
|
# Write your rules below.
|
||||||
|
|
||||||
# dae arms DNS rush-answer filter so we can use 8.8.8.8 regardless of DNS pollution.
|
# 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"
|
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()
|
log := logrus.New()
|
||||||
|
|
||||||
var level logrus.Level
|
level, err := logrus.ParseLevel(logLevel)
|
||||||
switch verbose {
|
if err != nil {
|
||||||
case 0:
|
|
||||||
level = logrus.WarnLevel
|
|
||||||
case 1:
|
|
||||||
level = logrus.InfoLevel
|
level = logrus.InfoLevel
|
||||||
case 2:
|
|
||||||
level = logrus.DebugLevel
|
|
||||||
default:
|
|
||||||
level = logrus.TraceLevel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.SetLevel(level)
|
log.SetLevel(level)
|
||||||
|
Reference in New Issue
Block a user