github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/examples/colorful_logging/main.go (about) 1 package main 2 3 import ( 4 "os" 5 "time" 6 7 . "github.com/v2pro/plz/countlog" 8 "github.com/v2pro/plz/countlog/output" 9 "github.com/v2pro/plz/countlog/output/async" 10 "github.com/v2pro/plz/countlog/output/hrf" 11 ) 12 13 func main() { 14 EventWriter = output.NewEventWriter(output.EventWriterConfig{ 15 Format: &hrf.Format{ShowTimestamp: true}, 16 Writer: async.NewAsyncWriter(async.AsyncWriterConfig{ 17 Writer: os.Stderr, 18 }), 19 }) 20 Trace("trace should be used in {scenario}", 21 "scenario", "unit test", 22 "comment", "we love tracing!") 23 Debug("debug should be used in {scenario}", 24 "scenario", "integration test, debug weird problem in production") 25 Info("info should be used as {scenario}", 26 "scenario", "the default production logging level") 27 Warn("warn should be used when {scenario}", 28 "scenario", "err != nil") 29 Error("error should be used when {scenario}", 30 "scenario", "err != nil returned to user") 31 Fatal("fatal is reserved for panic") 32 SetMinLevel(LevelDebug) 33 if ShouldLog(LevelTrace) { 34 Trace("if ShouldLog(LevelTrace) is necessary") 35 } 36 Trace("without if, the runtime cost is still minimal") 37 time.Sleep(time.Second) 38 }