Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module github.com/go-pkgz/lgr/_example | ||
|
||
go 1.12 | ||
|
||
require github.com/go-pkgz/lgr v0.0.0 | ||
|
||
replace github.com/go-pkgz/lgr => ../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/go-pkgz/lgr v0.6.1 h1:poohUbv/iguoQ6bzJ5j/Ubl1VcsjU+rzTbbxsKbkGXk= | ||
github.com/go-pkgz/lgr v0.6.1/go.mod h1:hBM1NM/SoYdlrykgdgJWGrZ/TM/XaZIjRbJfx7NkMm8= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import "github.com/go-pkgz/lgr" | ||
|
||
// Logger defines application's logger interface. Note - it doesn't introduce any dependency on lgr | ||
// and can be replaced with anything providing Logf function | ||
type Logger interface { | ||
Logf(format string, args ...interface{}) | ||
} | ||
|
||
func main() { | ||
l := lgr.New(lgr.Format(lgr.FullDebug)) // create lgr instance | ||
logConsumer(l) // pass logger to consumer | ||
|
||
l2 := lgr.New(lgr.Debug, lgr.Format(lgr.ShortDebug)) // create lgr instance, debug enabled | ||
logConsumer(l2) // pass logger to consumer | ||
|
||
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 | ||
} | ||
|
||
// consumer example with Logger passed in | ||
func logConsumer(l Logger) { | ||
l.Logf("INFO test 12345") | ||
l.Logf("DEBUG something") // will be printed for logger with Debug enabled | ||
} | ||
|
||
func logWithGlobal() { | ||
lgr.Printf("WARN test 9876543") // print to default logger | ||
} |