Skip to content

Commit 4f34608

Browse files
authored
Merge pull request #101 from anytypeio/add-zap-url
Add an option to pass URL to zap
2 parents 0016c0b + 264b187 commit 4f34608

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

setup.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
envLoggingFmt = "GOLOG_LOG_FMT"
3131

3232
envLoggingFile = "GOLOG_FILE" // /path/to/file
33+
envLoggingURL = "GOLOG_URL" // url that will be processed by sink in the zap
34+
3335
envLoggingOutput = "GOLOG_OUTPUT" // possible values: stdout|stderr|file combine multiple values with '+'
3436
)
3537

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

5759
// File is a path to a file that logs will be written to.
5860
File string
61+
62+
// URL with schema supported by zap. Use zap.RegisterSink
63+
URL string
5964
}
6065

6166
// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
@@ -107,6 +112,9 @@ func SetupLogging(cfg Config) {
107112
outputPaths = append(outputPaths, path)
108113
}
109114
}
115+
if len(cfg.URL) > 0 {
116+
outputPaths = append(outputPaths, cfg.URL)
117+
}
110118

111119
ws, _, err := zap.Open(outputPaths...)
112120
if err != nil {
@@ -265,6 +273,7 @@ func configFromEnv() Config {
265273
cfg.Stderr = false
266274
}
267275

276+
cfg.URL = os.Getenv(envLoggingURL)
268277
output := os.Getenv(envLoggingOutput)
269278
outputOptions := strings.Split(output, "+")
270279
for _, opt := range outputOptions {
@@ -277,6 +286,10 @@ func configFromEnv() Config {
277286
if cfg.File == "" {
278287
fmt.Fprint(os.Stderr, "please specify a GOLOG_FILE value to write to")
279288
}
289+
case "url":
290+
if cfg.URL == "" {
291+
fmt.Fprint(os.Stderr, "please specify a GOLOG_URL value to write to")
292+
}
280293
}
281294
}
282295

0 commit comments

Comments
 (0)