Tree @f0a3942 (Download .tar.gz)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | # package log `package log` provides a minimal interface for structured logging in services. It may be wrapped to encode conventions, enforce type-safety, etc. It can be used for both typical application log events, and log-structured data streams. ## Rationale TODO ## Usage Typical application logging. ```go import ( "os" "github.com/go-kit/kit/log" ) func main() { logger := log.NewLogfmtLogger(os.Stderr) logger.Log("question", "what is the meaning of life?", "answer", 42) } ``` Output: ``` question="what is the meaning of life?" answer=42 ``` Contextual logging. ```go func handle(logger log.Logger, req *Request) { ctx := log.NewContext(logger).With("txid", req.TransactionID, "query", req.Query) ctx.Log() answer, err := process(ctx, req.Query) if err != nil { ctx.Log("err", err) return } ctx.Log("answer", answer) } ``` Output: ``` txid=12345 query="some=query" txid=12345 query="some=query" answer=42 ``` Redirect stdlib log to gokit logger. ```go import ( "os" stdlog "log" kitlog "github.com/go-kit/kit/log" ) func main() { logger := kitlog.NewJSONLogger(os.Stdout) stdlog.SetOutput(kitlog.NewStdlibAdapter(logger)) stdlog.Print("I sure like pie") } ``` Output ``` {"msg":"I sure like pie","ts":"2016/01/28 19:41:08"} ``` Adding a timestamp to contextual logs ```go func handle(logger log.Logger, req *Request) { ctx := log.NewContext(logger).With("ts", log.DefaultTimestampUTC, "query", req.Query) ctx.Log() answer, err := process(ctx, req.Query) if err != nil { ctx.Log("err", err) return } ctx.Log("answer", answer) } ``` Output ``` ts=2016-01-29T00:46:04Z query="some=query" ts=2016-01-29T00:46:04Z query="some=query" answer=42 ``` Adding caller info to contextual logs ```go func handle(logger log.Logger, req *Request) { ctx := log.NewContext(logger).With("caller", log.DefaultCaller, "query", req.Query) ctx.Log() answer, err := process(ctx, req.Query) if err != nil { ctx.Log("err", err) return } ctx.Log("answer", answer) } ``` Output ``` caller=logger.go:20 query="some=query" caller=logger.go:28 query="some=query" answer=42 ``` |
History of log @f0a3942f45dbca02c2b39d1e0a006ae2da37e4ce
- gofmt -s -w Peter Bourgon 8 years ago
- Updated readme with more example usage. Nicholas Johns 8 years ago
- log/levels: Remove unused method parameters left from old API. Chris Hines 8 years ago
- Make levels API more composable. Chris Hines 8 years ago
- fixed comments Olivier Gagnon 8 years ago
- json logger will now call fmt.Stringer if the type does not implement json.Marshaller or encoding.TextMarshaler Olivier Gagnon 8 years ago
- Unify logging idioms Peter Bourgon 8 years ago
- log: Fix parsing with special characters juRiii 8 years ago
- log: Fix StdlibAdapter parsing of Windows file paths when stdlib log has the Llongfile flag set. juRiii 8 years ago
- log: Test DefaultCaller with JSON logger. Chris Hines 8 years ago
- Simplify package log/term's exported API. Chris Hines 8 years ago
- Add some polish. Chris Hines 8 years ago
- Improve docs. Chris Hines 8 years ago
- Simplify ColorLogger concurrency story. Chris Hines 8 years ago
- Target comments by Chris Hines Tamás Gulácsi 8 years ago
- add NewColorLogger Tamás Gulácsi 8 years ago
- Copy gopkg.in/inconshreveable/log15.v2/term to log/term Tamás Gulácsi 8 years ago
- update log README sbl 8 years ago
- Take care that log.Context.Log has a consistent function stack depth when binding log.Valuers. Chris Hines 8 years ago
- Use NopLogger in tests. Chris Hines 8 years ago
- Code review updates. Chris Hines 8 years ago
- Recover from panics caused by dereferencing a nil pointer to a value receiver implementation of the fmt.Stringer or error interfaces. Chris Hines 8 years ago
- Append ErrMissingValue to odd length keyvals rather than panic. Chris Hines 8 years ago
- Remove redundant and wrongly named test. Chris Hines 8 years ago
- Merge pull request #79 from go-kit/zipkin-enhancements Peter Bourgon 8 years ago
- log/levels: improve test coverage Peter Bourgon 8 years ago
- Add support for a fixed sampling rate Peter Bourgon 8 years ago
- Document implementation tradeoff and reason for choosing to favor a cheap WIth method at the expense of the Log method. Chris Hines 8 years ago
- Combine config and Levels structs. Chris Hines 8 years ago
- log: fix some comments Peter Bourgon 8 years ago