Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 5065abb

Browse files
committed
updated README
1 parent 2e3e7d8 commit 5065abb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,50 @@ output:
7575
time="2018-03-04T13:12:35-08:00" level=debug msg="this is a debug message"
7676
```
7777

78+
### Zerolog Logger
79+
This shim allows you to use [zerolog](https://github.com/rs/zerolog) as your logging implementation. If you pass `nil` into `New(...)`,
80+
you will get a default `zerolog.Logger` writing to `stdout` with a timestamp attached.
81+
82+
Alternatively, you can pass your own instance of `zerolog.Logger` to `New(...)`.
83+
84+
Using the `zerolog` default logger:
85+
```go
86+
import "github.com/InVisionApp/go-logger/shims/zerolog"
87+
88+
func main() {
89+
logger := zerolog.New(nil)
90+
logger.Debug("this is a debug message!")
91+
}
92+
93+
```
94+
95+
Using your own logger:
96+
```go
97+
import (
98+
"os"
99+
100+
zl "github.com/rs/zerolog"
101+
"github.com/InVisionApp/go-logger/shims/zerolog"
102+
)
103+
104+
func main() {
105+
// zerolog is a structured logger by default
106+
structuredLogger := zl.New(os.Stdout).Logger()
107+
sLogger := zerolog.New(structuredLogger)
108+
sLogger.Debug("debug message")
109+
// {"level":"debug", "message":"debug message"}
110+
111+
// If you want to use zerolog for human-readable console logging,
112+
// you create a ConsoleWriter and use it as your io.Writer implementation
113+
consoleLogger := zl.New(zl.ConsoleWriter{
114+
Out: os.Stdout,
115+
})
116+
cLogger := zerolog.New(consoleLogger)
117+
cLogger.Debug("debug message")
118+
// |DEBUG| debug message
119+
}
120+
```
121+
78122
### Test Logger
79123
The test logger is for capturing logs during the execution of a test. It writes the logs to a byte buffer which can be dumped and inspected. It also tracks a call count of the total number of times the logger has been called.
80124
**_Note:_** this logger is not meant to be used in production. It is purely designed for use in tests.

0 commit comments

Comments
 (0)