A README.md => README.md +56 -0
@@ 0,0 1,56 @@
+clog
+===
+
+[![GoDoc](https://godoc.org/github.com/Kochava/clog?status.svg)](https://godoc.org/github.com/Kochava/clog)
+
+ go get github.com/Kochava/clog
+
+clog is a simple package for initializing a [Zap][] logger and attaching it to
+a context, along with functions for logging from the context-attached logger or
+associating new fields to the logger.
+
+Generally speaking this is a bad use of the context package, but utility won out
+over passing both a context and a logger around all the time. In particular,
+this is useful for passing a request-scoped logger through different
+http.Handler implementations that otherwise do not support Zap.
+
+[Zap]: https://go.uber.org/zap
+
+
+Usage
+---
+
+A few examples of basic usage follow.
+
+### Initialize a logger
+
+```go
+// Create a logger at info level with a production configuration.
+l, err := clog.New(zap.InfoLevel, false)
+if err != nil {
+ ...
+}
+l.Info("Ready")
+```
+
+### Attach a logger to a context
+
+```go
+// var l *zap.Logger
+
+// Attach the logger, l, to a context:
+ctx := clog.WithLogger(context.Background(), l)
+
+// Attach fields to the logger:
+ctx = clog.With(ctx, zap.Int("field", 1234))
+
+// Log at info level:
+clog.Info(ctx, "Log message")
+```
+
+
+License
+---
+
+clog is made available under the ISC license. A copy of it can be found in the
+repository in the `COPYING` file.
M clog.go => clog.go +2 -0
@@ 1,3 1,5 @@
+// Package clog is a convenience package for passing Zap loggers through
+// contexts.
package clog
import (
M go.mod => go.mod +4 -0
@@ 1,6 1,10 @@
module github.com/Kochava/clog
+go 1.12
+
require (
+ github.com/pkg/errors v0.9.1 // indirect
+ github.com/stretchr/testify v1.4.0 // indirect
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1
M go.sum => go.sum +13 -0
@@ 1,6 1,19 @@
+github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
+github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=