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

63 lines
1.2 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-20 01:19:42 -04:00
initLogger()
}
// 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-20 01:19:42 -04:00
initLogger()
return err
}
// Init initialises the Log object and return it
2023-07-20 01:19:42 -04:00
func initLogger() {
// 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
}
err := logger.Configure(&logger.Config{
LogThreshold: logLevel,
Formatter: Configuration.Log.Format,
})
if err != nil {
logger.Error("LoggerConfigurationError", err)
}
}
// GetLogLevel returns the logger const level
func GetLogLevel() logger.Level {
return logLevel
}