Skip to content

Commit

Permalink
add an option to pass URL to z
Browse files Browse the repository at this point in the history
  • Loading branch information
requilence committed Aug 10, 2020
1 parent 0016c0b commit 270af48
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 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,11 @@ 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

Fields []zap.Field
}

// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
Expand Down Expand Up @@ -107,6 +114,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 +275,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 +288,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

0 comments on commit 270af48

Please sign in to comment.