mirror of
https://github.com/mudler/luet.git
synced 2025-07-17 00:41:45 +00:00
Added option for enable log to file.
Now it's possible logging to file is handled by the enable_logfile option and by the path. From cli is now possible: * enable log to file with the option --enable-logfile * modify the logfile path with the option --logfile/-l <path>
This commit is contained in:
parent
993bcf9adf
commit
fe5ab9246f
12
cmd/root.go
12
cmd/root.go
@ -92,7 +92,7 @@ func LoadConfig(c *config.LuetConfig) error {
|
|||||||
|
|
||||||
NewSpinner()
|
NewSpinner()
|
||||||
|
|
||||||
if c.GetLogging().Path != "" {
|
if c.GetLogging().EnableLogFile && c.GetLogging().Path != "" {
|
||||||
// Init zap logger
|
// Init zap logger
|
||||||
err = ZapLogger()
|
err = ZapLogger()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -152,6 +152,9 @@ func init() {
|
|||||||
pflags.StringVar(&cfgFile, "config", "", "config file (default is $HOME/.luet.yaml)")
|
pflags.StringVar(&cfgFile, "config", "", "config file (default is $HOME/.luet.yaml)")
|
||||||
pflags.BoolP("debug", "d", false, "verbose output")
|
pflags.BoolP("debug", "d", false, "verbose output")
|
||||||
pflags.Bool("fatal", false, "Enables Warnings to exit")
|
pflags.Bool("fatal", false, "Enables Warnings to exit")
|
||||||
|
pflags.Bool("enable-logfile", false, "Enable log to file")
|
||||||
|
pflags.StringP("logfile", "l", config.LuetCfg.GetLogging().Path,
|
||||||
|
"Logfile path. Empty value disable log to file.")
|
||||||
|
|
||||||
sameOwner := false
|
sameOwner := false
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
@ -166,10 +169,13 @@ func init() {
|
|||||||
pflags.Bool("same-owner", sameOwner, "Maintain same owner on uncompress.")
|
pflags.Bool("same-owner", sameOwner, "Maintain same owner on uncompress.")
|
||||||
pflags.Int("concurrency", runtime.NumCPU(), "Concurrency")
|
pflags.Int("concurrency", runtime.NumCPU(), "Concurrency")
|
||||||
|
|
||||||
config.LuetCfg.Viper.BindPFlag("general.same_owner", pflags.Lookup("same-owner"))
|
config.LuetCfg.Viper.BindPFlag("logging.enable_logfile", pflags.Lookup("enable-logfile"))
|
||||||
config.LuetCfg.Viper.BindPFlag("general.debug", pflags.Lookup("debug"))
|
config.LuetCfg.Viper.BindPFlag("logging.path", pflags.Lookup("logfile"))
|
||||||
|
|
||||||
config.LuetCfg.Viper.BindPFlag("general.concurrency", pflags.Lookup("concurrency"))
|
config.LuetCfg.Viper.BindPFlag("general.concurrency", pflags.Lookup("concurrency"))
|
||||||
|
config.LuetCfg.Viper.BindPFlag("general.debug", pflags.Lookup("debug"))
|
||||||
config.LuetCfg.Viper.BindPFlag("general.fatal_warnings", pflags.Lookup("fatal"))
|
config.LuetCfg.Viper.BindPFlag("general.fatal_warnings", pflags.Lookup("fatal"))
|
||||||
|
config.LuetCfg.Viper.BindPFlag("general.same_owner", pflags.Lookup("same-owner"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initConfig reads in config file and ENV variables if set.
|
// initConfig reads in config file and ENV variables if set.
|
||||||
|
@ -4,8 +4,11 @@
|
|||||||
# Logging configuration section:
|
# Logging configuration section:
|
||||||
# ---------------------------------------------
|
# ---------------------------------------------
|
||||||
# logging:
|
# logging:
|
||||||
|
# # Enable loggging to file (if path is not empty)
|
||||||
|
# enable_logfile: false
|
||||||
|
#
|
||||||
# Leave empty to skip logging to file.
|
# Leave empty to skip logging to file.
|
||||||
# path: ""
|
# path: "/var/log/luet.log"
|
||||||
#
|
#
|
||||||
# Set logging level: error|warning|info|debug
|
# Set logging level: error|warning|info|debug
|
||||||
# level: "info"
|
# level: "info"
|
||||||
|
@ -37,9 +37,10 @@ var LuetCfg = NewLuetConfig(v.GetViper())
|
|||||||
var AvailableResolvers = strings.Join([]string{solver.QLearningResolverType}, " ")
|
var AvailableResolvers = strings.Join([]string{solver.QLearningResolverType}, " ")
|
||||||
|
|
||||||
type LuetLoggingConfig struct {
|
type LuetLoggingConfig struct {
|
||||||
Path string `mapstructure:"path"`
|
Path string `mapstructure:"path"`
|
||||||
JsonFormat bool `mapstructure:"json_format"`
|
EnableLogFile bool `mapstructure:"enable_logfile"`
|
||||||
Level string `mapstructure:"level"`
|
JsonFormat bool `mapstructure:"json_format"`
|
||||||
|
Level string `mapstructure:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LuetGeneralConfig struct {
|
type LuetGeneralConfig struct {
|
||||||
@ -205,7 +206,8 @@ func NewLuetConfig(viper *v.Viper) *LuetConfig {
|
|||||||
|
|
||||||
func GenDefault(viper *v.Viper) {
|
func GenDefault(viper *v.Viper) {
|
||||||
viper.SetDefault("logging.level", "info")
|
viper.SetDefault("logging.level", "info")
|
||||||
viper.SetDefault("logging.path", "")
|
viper.SetDefault("logging.enable_logfile", false)
|
||||||
|
viper.SetDefault("logging.path", "/var/log/luet.log")
|
||||||
viper.SetDefault("logging.json_format", false)
|
viper.SetDefault("logging.json_format", false)
|
||||||
|
|
||||||
viper.SetDefault("general.concurrency", runtime.NumCPU())
|
viper.SetDefault("general.concurrency", runtime.NumCPU())
|
||||||
@ -318,9 +320,10 @@ func (c *LuetLoggingConfig) SetLogLevel(s string) {
|
|||||||
func (c *LuetLoggingConfig) String() string {
|
func (c *LuetLoggingConfig) String() string {
|
||||||
ans := fmt.Sprintf(`
|
ans := fmt.Sprintf(`
|
||||||
logging:
|
logging:
|
||||||
|
enable_logfile: %t
|
||||||
path: %s
|
path: %s
|
||||||
json_format: %t
|
json_format: %t
|
||||||
level: %s`, c.Path, c.JsonFormat, c.Level)
|
level: %s`, c.EnableLogFile, c.Path, c.JsonFormat, c.Level)
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user