Skip to content

Commit 3ef746c

Browse files
committed
README: add example for multiple loggers
[SKIP CI]
1 parent 953f720 commit 3ef746c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ func init() {
8080

8181
Other builtin loggers are file (`log.ModeFile`), Slack (`log.ModeSlack`) and Discord (`log.Discord`), see later in the documentation for usage details.
8282

83+
### Multiple Loggers
84+
85+
You can have multiple loggers in different modes with levels.
86+
87+
```go
88+
func init() {
89+
err := log.New(log.ModeConsole)
90+
if err != nil {
91+
panic("unable to create new logger: " + err.Error())
92+
}
93+
err := log.New(log.ModeFile, log.FileConfig{
94+
Level: log.LevelInfo,
95+
Filename: "clog.log",
96+
})
97+
if err != nil {
98+
panic("unable to create new logger: " + err.Error())
99+
}
100+
}
101+
```
102+
103+
In this example, all logs will be printed to console, and only logs with level Info or higher (i.e. Warn, Error and Fatal) will be written into file.
104+
83105
### Caller Location
84106

85107
When using `log.Error` and `log.Fatal` functions, the caller location is written along with logs.

0 commit comments

Comments
 (0)