Skip to content

Commit 7cf5571

Browse files
Merge branch 'master' into v2
2 parents d56b9c8 + 9d1cc30 commit 7cf5571

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

Diff for: README.md

+22-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![obligatory xkcd](http://imgs.xkcd.com/comics/standards.png)
22

3-
# log15
3+
# log15 [![godoc reference](https://godoc.org/gopkg.in/inconshreveable/log15.v2?status.png)](https://godoc.org/gopkg.in/inconshreveable/log15.v2)
44

55
Package log15 provides an opinionated, simple toolkit for best-practice logging that is both human and machine readable. It is modeled after the standard library's io and net/http packages.
66

@@ -14,49 +14,45 @@ Package log15 provides an opinionated, simple toolkit for best-practice logging
1414
- Built-in support for logging to files, streams, syslog, and the network
1515
- Support for forking records to multiple handlers, buffering records for output, failing over from failed handler writes, + more
1616

17-
## Documentation
18-
19-
The package documentation is extensive and complete. Browse on godoc:
20-
21-
#### [log15 API Documentation](https://godoc.org/gopkg.in/inconshreveable/log15.v2)
22-
2317
## Versioning
2418
The API of the master branch of log15 should always be considered unstable. Using a stable version
2519
of the log15 package is supported by gopkg.in. Include your dependency like so:
2620

2721
import log "gopkg.in/inconshreveable/log15.v2"
2822

29-
You can also vendor log15 with a tool like Godep.
30-
3123
## Examples
3224

33-
// all loggers can have key/value context
34-
srvlog := log.New("module", "app/server")
25+
```go
26+
// all loggers can have key/value context
27+
srvlog := log.New("module", "app/server")
3528

36-
// all log messages can have key/value context
37-
srvlog.Warn("abnormal conn rate", "rate", curRate, "low", lowRate, "high", highRate)
29+
// all log messages can have key/value context
30+
srvlog.Warn("abnormal conn rate", "rate", curRate, "low", lowRate, "high", highRate)
3831

39-
// child loggers with inherited context
40-
connlog := srvlog.New("raddr", c.RemoteAddr())
41-
connlog.Info("connection open")
32+
// child loggers with inherited context
33+
connlog := srvlog.New("raddr", c.RemoteAddr())
34+
connlog.Info("connection open")
4235

43-
// lazy evaluation
44-
connlog.Debug("ping remote", "latency", log.Lazy(pingRemote))
36+
// lazy evaluation
37+
connlog.Debug("ping remote", "latency", log.Lazy(pingRemote))
4538

46-
// flexible configuration
47-
srvlog.SetHandler(log.MultiHandler(
48-
log.StreamHandler(os.Stderr, log.LogfmtFormat()),
49-
log.LvlFilterHandler(
50-
log.LvlError,
51-
log.Must.FileHandler("errors.json", log.JsonHandler())))
39+
// flexible configuration
40+
srvlog.SetHandler(log.MultiHandler(
41+
log.StreamHandler(os.Stderr, log.LogfmtFormat()),
42+
log.LvlFilterHandler(
43+
log.LvlError,
44+
log.Must.FileHandler("errors.json", log.JsonHandler())))
45+
```
5246

5347
## FAQ
5448

5549
### The varargs style is brittle and error prone! Can I have type saftey please?
5650
Yes. Use log.Ctx:
5751

58-
srvlog := log.New(log.Ctx{"module": "app/server"})
59-
srvlog.Warn("abnormal conn rate", log.Ctx{"rate": curRate, "low": lowRate, "high": highRate})
52+
```go
53+
srvlog := log.New(log.Ctx{"module": "app/server"})
54+
srvlog.Warn("abnormal conn rate", log.Ctx{"rate": curRate, "low": lowRate, "high": highRate})
55+
```
6056

6157
## License
6258
Apache

Diff for: log15_test.go

+19
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,25 @@ func TestLogContext(t *testing.T) {
189189
}
190190
}
191191

192+
func TestMapCtx(t *testing.T) {
193+
t.Parallel()
194+
195+
l, _, r := testLogger()
196+
l.Crit("test", Ctx{"foo": "bar"})
197+
198+
if len(r.Ctx) != 2 {
199+
t.Fatalf("Wrong context length, got %d, expected %d", len(r.Ctx), 2)
200+
}
201+
202+
if r.Ctx[0] != "foo" {
203+
t.Fatalf("Wrong context key, got %s expected %s", r.Ctx[0], "foo")
204+
}
205+
206+
if r.Ctx[1] != "bar" {
207+
t.Fatalf("Wrong context value, got %s expected %s", r.Ctx[1], "bar")
208+
}
209+
}
210+
192211
func TestLvlFilterHandler(t *testing.T) {
193212
t.Parallel()
194213

Diff for: logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
121121
normalizedSuffix := normalize(suffix)
122122
newCtx := make([]interface{}, len(prefix)+len(normalizedSuffix))
123123
n := copy(newCtx, prefix)
124-
copy(newCtx[n:], suffix)
124+
copy(newCtx[n:], normalizedSuffix)
125125
return newCtx
126126
}
127127

0 commit comments

Comments
 (0)