Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for log formats #36

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions cmd/gitlab-ci-crawler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ var cfg crawler.Config
var neo4jcfg neo4j.Config

func init() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
if err := crawler.ParseConfig(&cfg); err != nil {
log.Fatal().Err(err).Msg("failed to configure crawler")
log.Fatal().Err(err).Msg("failed to parse crawler config")
}

switch cfg.LogFormat {
case "text":
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout})
case "json":
log.Logger = log.Output(os.Stdout)
default:
log.Fatal().
Str("LogFormat", cfg.LogFormat).
Msg("unsupported log format")
}

zerolog.SetGlobalLevel(zerolog.Level(cfg.LogLevel))
Expand Down
3 changes: 2 additions & 1 deletion internal/crawler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ type Config struct {
HTTPClientTimeout time.Duration `conf:"default:5s,short:x,env:HTTP_CLIENT_TIMEOUT"`
// There should be global config composition maybe? For not this lives here
// though this is the global log level
LogLevel int `conf:"default:1,env:LOG_LEVEL"`
LogLevel int `conf:"default:1,env:LOG_LEVEL"`
LogFormat string `conf:"default:json,env:LOG_FORMAT"`
}

func ParseConfig(cfg *Config) error {
Expand Down