github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/examples/compact_logging/main.go (about)

     1  package main
     2  
     3  import (
     4  	. "github.com/v2pro/plz/countlog"
     5  	"github.com/v2pro/plz/countlog/output"
     6  	"github.com/v2pro/plz/countlog/output/async"
     7  	"github.com/v2pro/plz/countlog/output/json"
     8  	"github.com/v2pro/plz/countlog/output/lumberjack"
     9  )
    10  
    11  func main() {
    12  	writer := async.NewAsyncWriter(async.AsyncWriterConfig{
    13  		Writer: &lumberjack.Logger{
    14  			Filename: "/tmp/test.log.json",
    15  		},
    16  	})
    17  	defer writer.Close()
    18  	EventWriter = output.NewEventWriter(output.EventWriterConfig{
    19  		Format: &json.JsonFormat{},
    20  		Writer: writer,
    21  	})
    22  	for i := 0; i < 10; i++ {
    23  		Info("game score calculated",
    24  			"playerId", 1328+i,
    25  			"scores", []int{1, 2, 7 + i})
    26  	}
    27  }