Skip to content

Commit

Permalink
chore: add a New() constructor + update examples
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
  • Loading branch information
moul committed Apr 23, 2021
1 parent ae16dbe commit 33ac2dd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 2 additions & 0 deletions AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,27 @@

[embedmd]:# (example_test.go /import\ / $)
```go
import "moul.io/zapconfig"
import (
"go.uber.org/zap/zapcore"

"moul.io/zapconfig"
)

func Example() {
logger := zapconfig.Configurator{}.MustBuild()
logger.Info("hello!")
}

func Example_configuration() {
logger := zapconfig.New().
EnableStacktrace().
SetLevel(zapcore.DebugLevel).
SetOutputPath("stderr").
SetOutputPaths([]string{"stderr", "stdout", "./path/to/log.txt"}).
SetPreset("light-console").
MustBuild()
logger.Info("hello!")
}
```

## Install
Expand Down
17 changes: 16 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
package zapconfig_test

import "moul.io/zapconfig"
import (
"go.uber.org/zap/zapcore"

"moul.io/zapconfig"
)

func Example() {
logger := zapconfig.Configurator{}.MustBuild()
logger.Info("hello!")
}

func Example_configuration() {
logger := zapconfig.New().
EnableStacktrace().
SetLevel(zapcore.DebugLevel).
SetOutputPath("stderr").
SetOutputPaths([]string{"stderr", "stdout", "./path/to/log.txt"}).
SetPreset("light-console").
MustBuild()
logger.Info("hello!")
}
6 changes: 0 additions & 6 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions zapconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ type Configurator struct {
configErr error
}

// New instanciates a Configurator.
func New() *Configurator {
return &Configurator{}
}

// SetOutputPath sets zap.Config.OutputPaths and c.Config.ErrorOutputPaths with the given path.
func (c *Configurator) SetOutputPath(dest string) *Configurator {
c.opts.OutputPaths = []string{dest}
Expand Down

0 comments on commit 33ac2dd

Please sign in to comment.