M README.md => README.md +3 -2
@@ 26,9 26,10 @@ A few examples of basic usage follow.
```go
// Create a logger at info level with a production configuration.
-l, err := clog.New(zap.InfoLevel, false)
+level := zap.NewAtomicLevelAt(zap.InfoLevel)
+l, err := clog.New(level, false)
if err != nil {
- ...
+ panic(err)
}
l.Info("Ready")
```
A example_test.go => example_test.go +27 -0
@@ 0,0 1,27 @@
+package clog_test
+
+import (
+ "context"
+
+ "github.com/Kochava/clog"
+ "go.uber.org/zap"
+)
+
+func ExampleNew() {
+ // Create a logger at info level with a production configuration.
+ level := zap.NewAtomicLevelAt(zap.InfoLevel)
+ l, err := clog.New(level, false)
+ if err != nil {
+ panic(err)
+ }
+ l.Info("Ready")
+
+ // 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")
+}