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 an option to pass URL to zap #101

Merged
merged 1 commit into from
Sep 4, 2020
Merged
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
13 changes: 13 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
envLoggingFmt = "GOLOG_LOG_FMT"

envLoggingFile = "GOLOG_FILE" // /path/to/file
envLoggingURL = "GOLOG_URL" // url that will be processed by sink in the zap

envLoggingOutput = "GOLOG_OUTPUT" // possible values: stdout|stderr|file combine multiple values with '+'
)

Expand All @@ -56,6 +58,9 @@ type Config struct {

// File is a path to a file that logs will be written to.
File string

// URL with schema supported by zap. Use zap.RegisterSink
URL string
}

// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
Expand Down Expand Up @@ -107,6 +112,9 @@ func SetupLogging(cfg Config) {
outputPaths = append(outputPaths, path)
}
}
if len(cfg.URL) > 0 {
outputPaths = append(outputPaths, cfg.URL)
}

ws, _, err := zap.Open(outputPaths...)
if err != nil {
Expand Down Expand Up @@ -265,6 +273,7 @@ func configFromEnv() Config {
cfg.Stderr = false
}

cfg.URL = os.Getenv(envLoggingURL)
output := os.Getenv(envLoggingOutput)
outputOptions := strings.Split(output, "+")
for _, opt := range outputOptions {
Expand All @@ -277,6 +286,10 @@ func configFromEnv() Config {
if cfg.File == "" {
fmt.Fprint(os.Stderr, "please specify a GOLOG_FILE value to write to")
}
case "url":
if cfg.URL == "" {
fmt.Fprint(os.Stderr, "please specify a GOLOG_URL value to write to")
}
}
}

Expand Down