From 264b187bb04f8114cf308c36ba739f12327ff29a Mon Sep 17 00:00:00 2001 From: requilence Date: Tue, 11 Aug 2020 00:06:35 +0300 Subject: [PATCH] add an option to pass URL to zap --- setup.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/setup.go b/setup.go index 801e5b3f2b2b..9820cf0997ce 100644 --- a/setup.go +++ b/setup.go @@ -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") + } } }