Skip to content

Commit 63767a5

Browse files
authored
Add Example for Multiple Outputs using Multiwriter (#198)
Fixes #73
1 parent f83de79 commit 63767a5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,25 @@ if err := http.ListenAndServe(":8080", nil); err != nil {
469469
}
470470
```
471471

472+
## Multiple Log Output
473+
`zerolog.MultiLevelWriter` may be used to send the log message to multiple outputs.
474+
In this example, we send the log message to both `os.Stdout` and the in-built ConsoleWriter.
475+
```go
476+
func main() {
477+
consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout}
478+
479+
multi := zerolog.MultiLevelWriter(consoleWriter, os.Stdout)
480+
481+
logger := zerolog.New(multi).With().Timestamp().Logger()
482+
483+
logger.Info().Msg("Hello World!")
484+
}
485+
486+
// Output (Line 1: Console; Line 2: Stdout)
487+
// 12:36PM INF Hello World!
488+
// {"level":"info","time":"2019-11-07T12:36:38+03:00","message":"Hello World!"}
489+
```
490+
472491
## Global Settings
473492

474493
Some settings can be changed and will by applied to all loggers:

0 commit comments

Comments
 (0)