github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/libs/log/logger.go (about) 1 package log 2 3 import ( 4 "io" 5 "sync" 6 7 kitlog "github.com/go-kit/log" 8 ) 9 10 const ( 11 // LogFormatPlain defines a logging format used for human-readable text-based 12 // logging that is not structured. Typically, this format is used for development 13 // and testing purposes. 14 LogFormatPlain string = "plain" 15 16 // LogFormatText defines a logging format used for human-readable text-based 17 // logging that is not structured. Typically, this format is used for development 18 // and testing purposes. 19 LogFormatText string = "text" 20 21 // LogFormatJSON defines a logging format for structured JSON-based logging 22 // that is typically used in production environments, which can be sent to 23 // logging facilities that support complex log parsing and querying. 24 LogFormatJSON string = "json" 25 26 // Supported loging levels 27 LogLevelDebug = "debug" 28 LogLevelInfo = "info" 29 LogLevelWarn = "warn" 30 LogLevelError = "error" 31 ) 32 33 // Logger defines a generic logging interface compatible with Tendermint. 34 type Logger interface { 35 Debug(msg string, keyVals ...interface{}) 36 Info(msg string, keyVals ...interface{}) 37 Error(msg string, keyVals ...interface{}) 38 39 With(keyVals ...interface{}) Logger 40 } 41 42 // syncWriter wraps an io.Writer that can be used in a Logger that is safe for 43 // concurrent use by multiple goroutines. 44 type syncWriter struct { 45 sync.Mutex 46 io.Writer 47 } 48 49 func newSyncWriter(w io.Writer) io.Writer { 50 return &syncWriter{Writer: w} 51 } 52 53 // Write writes p to the underlying io.Writer. If another write is already in 54 // progress, the calling goroutine blocks until the syncWriter is available. 55 func (w *syncWriter) Write(p []byte) (int, error) { 56 w.Lock() 57 defer w.Unlock() 58 return w.Writer.Write(p) 59 } 60 61 func NewSyncWriter(w io.Writer) io.Writer { 62 return kitlog.NewSyncWriter(w) 63 }