Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Apr 2, 2019
1 parent c58f6c4 commit a064eac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -60,7 +60,7 @@ Several predefined templates provided and can be passed directly to `lgr.Format`
User can make a custom template and pass it directly to `lgr.Format`. For example:

```go
lgr.Format(`{{.Level}} - {{.DT.Format "2006-01-02T15:04:05Z07:00") - {{.CallerPkg}} - {{.Message}}`)
lgr.Format(`{{.Level}} - {{.DT.Format "2006-01-02T15:04:05Z07:00"}} - {{.CallerPkg}} - {{.Message}}`)
```


Expand Down
21 changes: 14 additions & 7 deletions _example/main.go
Expand Up @@ -11,19 +11,26 @@ type Logger interface {
func main() {
l := lgr.New(lgr.Format(lgr.FullDebug)) // create lgr instance
logConsumer(l) // pass logger to consumer
// out: 2019/04/01 02:43:20.590 INFO (_example/main.go:31 main.logConsumer) test 12345

l2 := lgr.New(lgr.Debug, lgr.Format(lgr.ShortDebug)) // create lgr instance, debug enabled
logConsumer(l2) // pass logger to consumer
// out:
// 2019/04/01 02:43:20.591 INFO (_example/main.go:31) test 12345
// 2019/04/01 02:43:20.591 DEBUG (_example/main.go:32) something

// define custom output format
format := lgr.Format(`{{.Level}} - {{.DT.Format "2006-01-02T15:04:05Z07:00"}} - {{.CallerPkg}} - {{.Message}}`)
l3 := lgr.New(format)
logConsumer(l3)
// out: INFO - 2019-04-02T01:21:33-05:00 - _example - test 12345

logWithGlobal() // logging with default global logger
// out: 2019/04/01 02:43:20 WARN test 9876543

logWithGlobal() // logging with default global logger
lgr.Setup(lgr.Msec, lgr.LevelBraces) // change settings of global logger
logWithGlobal() // logging with modified global logger

// 2019/04/01 02:43:20.590 INFO (_example/main.go:31 main.logConsumer) test 12345
// 2019/04/01 02:43:20.591 INFO (_example/main.go:31) test 12345
// 2019/04/01 02:43:20.591 DEBUG (_example/main.go:32) something
// 2019/04/01 02:43:20 WARN test 9876543
// 2019/04/01 02:43:20.591 [WARN] test 9876543
// out: 2019/04/01 02:43:20.591 [WARN] test 9876543
}

// consumer example with Logger passed in
Expand Down

0 comments on commit a064eac

Please sign in to comment.