Skip to content

Commit 76d5270

Browse files
author
Arun Gopalpuri
committed
readme installation, quick guide
1 parent efbb37a commit 76d5270

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,69 @@
11
## Logger interface with implementations (Zap and Logrus)
22

3+
[![Build Status](https://api.travis-ci.com/arun0009/go-logger.svg?branch=master)](https://travis-ci.com/arun0009/go-logger)
4+
35
When we create go libraries in general we shouldn't be logging but at times we do have to log, debug what the
46
library is doing or trace the log.
57

68
We cannot implement a library with one log library and expect applications to use the same log library. We use two
79
of the popular log libraries [logrus](https://github.com/sirupsen/logrus) and [zap](https://github.com/uber-go/zap)
8-
and this `go-logger` library allows you to use either by using an interface.
10+
and this `go-logger` library allows you to use either one by using an interface.
11+
12+
You can add your implementation if you want to add more log libraries (e.g. zerolog).
13+
14+
## Installation
15+
16+
go get -u github.com/arun0009/go-logger
17+
18+
## Quick Start
19+
20+
[logrus](https://github.com/sirupsen/logrus) example
21+
22+
```go
23+
package main
24+
25+
import (
26+
"os"
27+
28+
"github.com/arun0009/go-logger/pkg/logger"
29+
"github.com/sirupsen/logrus"
30+
)
31+
32+
func main() {
33+
logrusLog := logrus.New()
34+
logrusLog.SetFormatter(&logrus.JSONFormatter{})
35+
logrusLog.SetOutput(os.Stdout)
36+
logrusLog.SetLevel(logrus.DebugLevel)
37+
log, _ := logger.NewLogrusLogger(logrusLog)
38+
log.WithFields(logger.Fields{
39+
"foo": "bar",
40+
}).Info("direct")
41+
}
42+
```
43+
44+
[zap](https://github.com/uber-go/zap) example
45+
46+
```go
47+
package main
48+
49+
import (
50+
"os"
51+
52+
"github.com/arun0009/go-logger/pkg/logger"
53+
"go.uber.org/zap"
54+
"go.uber.org/zap/zapcore"
55+
)
56+
57+
func main() {
58+
consoleEncoder := zapcore.NewJSONEncoder(zap.NewDevelopmentEncoderConfig())
59+
core := zapcore.NewCore(consoleEncoder,
60+
zapcore.Lock(zapcore.AddSync(os.Stderr)),
61+
zapcore.DebugLevel)
62+
zapLogger := zap.New(core)
63+
log, _ := logger.NewZapLogger(zapLogger)
64+
log.WithFields(logger.Fields{
65+
"foo": "bar",
66+
}).Info("direct")
67+
}
968

10-
You can add your implementation if you want to add more log libraries (e.g. zerolog).
69+
```

0 commit comments

Comments
 (0)