...

Source file src/github.com/go-kit/kit/log/stdlib.go

Documentation: github.com/go-kit/kit/log

     1  package log
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/go-kit/log"
     7  )
     8  
     9  // StdlibWriter implements io.Writer by invoking the stdlib log.Print. It's
    10  // designed to be passed to a Go kit logger as the writer, for cases where
    11  // it's necessary to redirect all Go kit log output to the stdlib logger.
    12  //
    13  // If you have any choice in the matter, you shouldn't use this. Prefer to
    14  // redirect the stdlib log to the Go kit logger via NewStdlibAdapter.
    15  type StdlibWriter = log.StdlibWriter
    16  
    17  // StdlibAdapter wraps a Logger and allows it to be passed to the stdlib
    18  // logger's SetOutput. It will extract date/timestamps, filenames, and
    19  // messages, and place them under relevant keys.
    20  type StdlibAdapter = log.StdlibAdapter
    21  
    22  // StdlibAdapterOption sets a parameter for the StdlibAdapter.
    23  type StdlibAdapterOption = log.StdlibAdapterOption
    24  
    25  // TimestampKey sets the key for the timestamp field. By default, it's "ts".
    26  func TimestampKey(key string) StdlibAdapterOption {
    27  	return log.TimestampKey(key)
    28  }
    29  
    30  // FileKey sets the key for the file and line field. By default, it's "caller".
    31  func FileKey(key string) StdlibAdapterOption {
    32  	return log.FileKey(key)
    33  }
    34  
    35  // MessageKey sets the key for the actual log message. By default, it's "msg".
    36  func MessageKey(key string) StdlibAdapterOption {
    37  	return log.MessageKey(key)
    38  }
    39  
    40  // Prefix configures the adapter to parse a prefix from stdlib log events. If
    41  // you provide a non-empty prefix to the stdlib logger, then your should provide
    42  // that same prefix to the adapter via this option.
    43  //
    44  // By default, the prefix isn't included in the msg key. Set joinPrefixToMsg to
    45  // true if you want to include the parsed prefix in the msg.
    46  func Prefix(prefix string, joinPrefixToMsg bool) StdlibAdapterOption {
    47  	return log.Prefix(prefix, joinPrefixToMsg)
    48  }
    49  
    50  // NewStdlibAdapter returns a new StdlibAdapter wrapper around the passed
    51  // logger. It's designed to be passed to log.SetOutput.
    52  func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer {
    53  	return log.NewStdlibAdapter(logger, options...)
    54  }
    55  

View as plain text