~nilium/clog

888d00e2e9f78344dea435af049a9768113cdc3c — Noel Cower 4 years ago ac899cc
Fix README example

Move it into example_test.go so that it can be checked as well.
2 files changed, 30 insertions(+), 2 deletions(-)

M README.md
A example_test.go
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")
}