Files
projectreshoot/internal/config/logger.go

37 lines
919 B
Go

package config
import (
"git.haelnorr.com/h/golib/env"
"git.haelnorr.com/h/golib/hlog"
"github.com/pkg/errors"
)
type HLOGConfig struct {
// ENV LOG_LEVEL: Log level for global logging. (default: info)
LogLevel hlog.Level
// ENV LOG_OUTPUT: Output method for the logger. (default: console)
// Valid options: "file", "console", "both"
LogOutput string
// ENV LOG_DIR: Path to create log files
LogDir string
}
func setupHLOG() (*HLOGConfig, error) {
logLevel, err := hlog.LogLevel(env.String("LOG_LEVEL", "info"))
if err != nil {
return nil, errors.Wrap(err, "hlog.LogLevel")
}
logOutput := env.String("LOG_OUTPUT", "console")
if logOutput != "both" && logOutput != "console" && logOutput != "file" {
return nil, errors.Errorf("Invalid LOG_OUTPUT: %s", logOutput)
}
cfg := &HLOGConfig{
LogLevel: logLevel,
LogOutput: logOutput,
LogDir: env.String("LOG_DIR", ""),
}
return cfg, nil
}