Skip to content

Commit

Permalink
Fix tests for Debug and add information about log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
apsdehal committed May 15, 2019
1 parent f85330a commit 1abdf89
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 11 additions & 2 deletions README.md
Expand Up @@ -43,6 +43,7 @@ func main () {
log.Critical("This is Critical!")
log.CriticalF("%+v", err)
// Debug
// Since default logging level is Info this won't print anything
log.Debug("This is Debug!")
log.DebugF("Here are some numbers: %d %d %f", 10, -3, 3.14)
// Give the Warning
Expand All @@ -67,11 +68,20 @@ func main () {
logger.SetDefaultFormat("%{message}")
log2, _ := logger.New("pkg", 1, os.Stdout)
log2.Error("This is Error!") // output: "This is Error!"

// Use log levels to set your log priority
log2.SetLogLevel(DebugLevel)
// This will be printed
log2.Debug("This is debug!")
log2.SetLogLevel(WarningLevel)
// This won't be printed
log2.Info("This is an error!")
}
```


# Formatting

By default all log messages have format that you can see above (on pic).
But you can override the default format and set format that you want.

Expand Down Expand Up @@ -112,7 +122,7 @@ Invalid verbs (like ```%{inv-verb```) will be treated as plain text.

# Tests

Run:
Run:
- `go test logger` to run test on logger.
- `go test -bench=.` for benchmarks.

Expand All @@ -130,4 +140,3 @@ Following contributors have made major contributions to go-logger:
## License

The [BSD 3-Clause license](http://opensource.org/licenses/BSD-3-Clause), the same as the [Go language](http://golang.org/LICENSE).

2 changes: 1 addition & 1 deletion logger.go
Expand Up @@ -464,8 +464,8 @@ func (info *Info) logLevelString() string {
"ERROR",
"WARNING",
"NOTICE",
"DEBUG",
"INFO",
"DEBUG",
}
return logLevels[info.Level-1]
}
8 changes: 6 additions & 2 deletions logger_test.go
Expand Up @@ -149,9 +149,13 @@ func TestLogger_SetFormat(t *testing.T) {
if err != nil || log == nil {
panic(err)
}

log.SetLogLevel(DebugLevel)
log.Debug("Test")
log.SetLogLevel(InfoLevel)

want := time.Now().Format("2006-01-02 15:04:05")
want = fmt.Sprintf("#1 %s logger_test.go:152 â–¶ DEB Test\n", want)
want = fmt.Sprintf("#1 %s logger_test.go:154 â–¶ DEB Test\n", want)
have := buf.String()
if have != want {
t.Errorf("\nWant: %sHave: %s", want, have)
Expand All @@ -176,7 +180,7 @@ func TestLogger_SetFormat(t *testing.T) {
"a{b pkgname "+
"a}b logger_test.go "+
"%%%% logger_test.go "+ // it's printf, escaping %, don't forget
"%%{171 "+
"%%{175 "+
" ERR "+
"%%{incorr_verb ERROR "+
" [This is Error!]\n",
Expand Down

0 comments on commit 1abdf89

Please sign in to comment.