nginx-proxy-manager-zh/backend/internal/config/config.go

62 lines
1.3 KiB
Go
Raw Normal View History

package config
import (
"fmt"
golog "log"
"npm/internal/logger"
"github.com/vrischmann/envconfig"
)
// Init will parse environment variables into the Env struct
2023-07-20 01:19:42 -04:00
func Init(version, commit *string) {
Version = *version
Commit = *commit
if err := envconfig.InitWithPrefix(&Configuration, "NPM"); err != nil {
fmt.Printf("%+v\n", err)
}
2023-07-30 23:49:11 -04:00
if err := initLogger(); err != nil {
logger.Error("LoggerConfigurationError", err)
}
}
// InitIPRanges will initialise the config for the ipranges command
2023-07-20 01:19:42 -04:00
func InitIPRanges(version, commit *string) error {
Version = *version
Commit = *commit
err := envconfig.InitWithPrefix(&Configuration, "NPM")
2023-07-30 23:49:11 -04:00
// nolint: errcheck, gosec
2023-07-20 01:19:42 -04:00
initLogger()
return err
}
// Init initialises the Log object and return it
2023-07-30 23:49:11 -04:00
func initLogger() error {
// this removes timestamp prefixes from logs
golog.SetFlags(0)
switch Configuration.Log.Level {
case "debug":
logLevel = logger.DebugLevel
case "warn":
logLevel = logger.WarnLevel
case "error":
logLevel = logger.ErrorLevel
default:
logLevel = logger.InfoLevel
}
2023-07-30 23:49:11 -04:00
return logger.Configure(&logger.Config{
LogThreshold: logLevel,
Formatter: Configuration.Log.Format,
})
}
// GetLogLevel returns the logger const level
func GetLogLevel() logger.Level {
return logLevel
}