adding logging to server

This commit is contained in:
2020-06-15 15:24:56 -04:00
parent d335549fd5
commit 88333417d4
10 changed files with 72 additions and 37 deletions

View File

@@ -7,6 +7,7 @@ import (
"path/filepath"
"github.com/deranjer/store"
"github.com/rs/zerolog"
)
// ConfigPath is the global path to the config that is injected from the main server package.
@@ -34,6 +35,28 @@ func FindConfig() (string, error) {
return "", fmt.Errorf("serverConfig.toml does not appear to be in the correct file format")
}
// SetLogLevel takes in the integer supplied and turns it into a log level
func SetLogLevel(loglevel int) (level zerolog.Level, err error) {
switch loglevel {
case -1:
return zerolog.TraceLevel, nil
case 0:
return zerolog.DebugLevel, nil
case 1:
return zerolog.InfoLevel, nil
case 2:
return zerolog.WarnLevel, nil
case 3:
return zerolog.ErrorLevel, nil
case 4:
return zerolog.FatalLevel, nil
case 5:
return zerolog.PanicLevel, nil
default:
return zerolog.InfoLevel, fmt.Errorf("incorrect log level set, setting it to info level")
}
}
// ValidateConfig will go through the entire config and do basic sanity checks and write valid values to the server struct if some are missing
func ValidateConfig(conf *GvcServerConfig, configPath string, version string) error {
if conf.Version == "" { // No version found, should we update it?

View File

@@ -8,6 +8,7 @@ import (
// GvcServerConfig will hold the base server settings
type GvcServerConfig struct {
LogFile string `toml:"logfile"` // Where to store the echo logs
LogLevel int `toml:"loglevel"` // Panic: 5, Fatal: 4, Error: 3, Warn: 2, Info: 1, debug: 0, trace: -1
DatabaseLocation string `toml:"databaselocation"` // Location of the database
Database *storm.DB // DB Handle for passing around
Version string `toml:"version"` // The server version