mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
use config file from the environment variable.
This commit is contained in:
parent
77e31bb1bc
commit
916222b6df
22
cmd/root.go
22
cmd/root.go
@ -37,16 +37,11 @@ func init() {
|
|||||||
zerolog.TimeFieldFormat = ""
|
zerolog.TimeFieldFormat = ""
|
||||||
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
||||||
|
|
||||||
if viper.GetBool("debug") {
|
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
||||||
}
|
|
||||||
|
|
||||||
console := zerolog.ConsoleWriter{Out: os.Stdout}
|
console := zerolog.ConsoleWriter{Out: os.Stdout}
|
||||||
|
|
||||||
if !viper.GetBool("logs") {
|
if !viper.GetBool("logs") {
|
||||||
log.Logger = log.Output(console)
|
log.Logger = log.Output(console)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
logs := filepath.Join(".", "logs")
|
logs := filepath.Join(".", "logs")
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
logs = "/var/log/neko"
|
logs = "/var/log/neko"
|
||||||
@ -81,9 +76,13 @@ func init() {
|
|||||||
//////
|
//////
|
||||||
// configs
|
// configs
|
||||||
//////
|
//////
|
||||||
config := viper.GetString("config")
|
config := viper.GetString("config") // Use config file from the flag.
|
||||||
|
if config == "" {
|
||||||
|
config = os.Getenv("NEKO_CONFIG") // Use config file from the environment variable.
|
||||||
|
}
|
||||||
|
|
||||||
if config != "" {
|
if config != "" {
|
||||||
viper.SetConfigFile(config) // Use config file from the flag.
|
viper.SetConfigFile(config)
|
||||||
} else {
|
} else {
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
viper.AddConfigPath("/etc/neko/")
|
viper.AddConfigPath("/etc/neko/")
|
||||||
@ -106,14 +105,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// debug mode from ENV or config
|
//////
|
||||||
if viper.GetBool("debug") {
|
// debug
|
||||||
|
//////
|
||||||
|
debug := viper.GetBool("debug")
|
||||||
|
if debug {
|
||||||
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
file := viper.ConfigFileUsed()
|
file := viper.ConfigFileUsed()
|
||||||
logger := log.With().
|
logger := log.With().
|
||||||
Bool("debug", viper.GetBool("debug")).
|
Bool("debug", debug).
|
||||||
Str("logging", viper.GetString("logs")).
|
Str("logging", viper.GetString("logs")).
|
||||||
Str("config", file).
|
Str("config", file).
|
||||||
Logger()
|
Logger()
|
||||||
|
Loading…
Reference in New Issue
Block a user