Unverified Commit 4f346089 authored by Jakub Sztandera's avatar Jakub Sztandera Committed by GitHub

Merge pull request #101 from anytypeio/add-zap-url

Add an option to pass URL to zap
parents 0016c0b4 264b187b
......@@ -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 '+'
)
......@@ -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
......@@ -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 {
......@@ -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 {
......@@ -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")
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment