github.com/oarkflow/log@v1.0.78/examples/main.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/oarkflow/log"
     7  )
     8  
     9  func main() {
    10  	w := []log.Writer{
    11  		&log.ConsoleWriter{ColorOutput: true, EndWithMessage: true},
    12  		&log.IOWriter{Writer: os.Stdout},
    13  	}
    14  	writer := log.MultiEntryWriter(w)
    15  	logr := log.Logger{
    16  		Level:      log.InfoLevel,
    17  		Caller:     1,
    18  		TimeField:  "date",
    19  		TimeFormat: "2006-01-02",
    20  		Writer:     &writer,
    21  	}
    22  	logger := log.With(&logr).Str("attr1", "12").Copy()
    23  	logger2 := log.With(&logger).Str("attr2", "1245").Copy()
    24  	logger2.Info().Str("foo", "bar").Int("number", 42).Msg("hi, phuslog")
    25  	logger2.Error().Msgf("foo=%s number=%d error=%+v", "bar", 42, "an error")
    26  }
    27  
    28  // Output:
    29  // {"date":"2024-05-11","level":"info","attr1":"12","attr2":"1245","foo":"bar","number":42,"trace_id":"1789189541429514240","host_platform":"localhost","message":"hi, phuslog"}
    30  // {"date":"2024-05-11","level":"error","attr1":"12","attr2":"1245","message":"foo=bar number=42 error=an error","trace_id":"1789189541555343360","host_platform":"localhost"}