github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/libs/log/oc_json_logger.go (about)

     1  package log
     2  
     3  import (
     4  	"io"
     5  
     6  	kitlog "github.com/go-kit/log"
     7  )
     8  
     9  // NewOCJSONLogger returns a Logger that encodes keyvals to the Writer as a
    10  // single JSON object. Each log event produces no more than one call to
    11  // w.Write. The passed Writer must be safe for concurrent use by multiple
    12  // goroutines if the returned Logger will be used concurrently.
    13  func NewOCJSONLogger(w io.Writer) Logger {
    14  	logger := kitlog.NewJSONLogger(w)
    15  	logger = kitlog.With(logger, "ts", kitlog.DefaultTimestampUTC)
    16  	return &ocLogger{logger}
    17  }
    18  
    19  // NewOCJSONLoggerNoTS is the same as NewOCJSONLogger, but without the
    20  // timestamp.
    21  func NewOCJSONLoggerNoTS(w io.Writer) Logger {
    22  	logger := kitlog.NewJSONLogger(w)
    23  	return &ocLogger{logger}
    24  }