~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/gopkg.in/inconshreveable/log15.v2/README.md

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
![obligatory xkcd](http://imgs.xkcd.com/comics/standards.png)
2
 
 
3
 
# log15 [![godoc reference](https://godoc.org/gopkg.in/inconshreveable/log15.v2?status.png)](https://godoc.org/gopkg.in/inconshreveable/log15.v2)
4
 
 
5
 
Package log15 provides an opinionated, simple toolkit for best-practice logging in Go (golang) that is both human and machine readable. It is modeled after the Go standard library's [`io`](http://golang.org/pkg/io/) and [`net/http`](http://golang.org/pkg/net/http/) packages and is an alternative to the standard library's [`log`](http://golang.org/pkg/log/) package. 
6
 
 
7
 
## Features
8
 
- A simple, easy-to-understand API
9
 
- Promotes structured logging by encouraging use of key/value pairs
10
 
- Child loggers which inherit and add their own private context
11
 
- Lazy evaluation of expensive operations
12
 
- Simple Handler interface allowing for construction of flexible, custom logging configurations with a tiny API.
13
 
- Color terminal support
14
 
- Built-in support for logging to files, streams, syslog, and the network
15
 
- Support for forking records to multiple handlers, buffering records for output, failing over from failed handler writes, + more
16
 
 
17
 
## Versioning
18
 
The API of the master branch of log15 should always be considered unstable. Using a stable version
19
 
of the log15 package is supported by gopkg.in. Include your dependency like so:
20
 
 
21
 
```go
22
 
import log "gopkg.in/inconshreveable/log15.v2"
23
 
```
24
 
 
25
 
## Examples
26
 
 
27
 
```go
28
 
// all loggers can have key/value context
29
 
srvlog := log.New("module", "app/server")
30
 
 
31
 
// all log messages can have key/value context 
32
 
srvlog.Warn("abnormal conn rate", "rate", curRate, "low", lowRate, "high", highRate)
33
 
 
34
 
// child loggers with inherited context
35
 
connlog := srvlog.New("raddr", c.RemoteAddr())
36
 
connlog.Info("connection open")
37
 
 
38
 
// lazy evaluation
39
 
connlog.Debug("ping remote", "latency", log.Lazy(pingRemote))
40
 
 
41
 
// flexible configuration
42
 
srvlog.SetHandler(log.MultiHandler(
43
 
    log.StreamHandler(os.Stderr, log.LogfmtFormat()),
44
 
    log.LvlFilterHandler(
45
 
        log.LvlError,
46
 
        log.Must.FileHandler("errors.json", log.JsonHandler())))
47
 
```
48
 
 
49
 
## FAQ
50
 
 
51
 
### The varargs style is brittle and error prone! Can I have type safety please?
52
 
Yes. Use `log.Ctx`:
53
 
 
54
 
```go
55
 
srvlog := log.New(log.Ctx{"module": "app/server"})
56
 
srvlog.Warn("abnormal conn rate", log.Ctx{"rate": curRate, "low": lowRate, "high": highRate})
57
 
```
58
 
 
59
 
## License
60
 
Apache