Documentation ¶
Overview ¶
The writer package is an event handler responsible for sending events to a generic IO writer.
Examples:
STDOUT/STDERR
logger := sawmill.NewLogger() logger.AddHandler("stdStreams", writer.NewStandardStreamsHandler()) # will go to STDERR logger.Warning("foo", sawmill.Fields{"bar": "baz"}) # will go to STDOUT logger.Info("foo", sawmill.Fiels{"pop": "tart"}) logger.Stop()
File appender
logger := sawmill.NewLogger() h, err := writer.Append("/var/log/foo", 0600, "") if err != nil { sawmill.Panic("error opening log file", sawmill.Fields{"error": err, "path": "/var/log/foo"}) } logger.AddHandler("logfile", h) logger.Info("FOO!", sawmill.Fields{"bar": "baz"})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTerminal ¶
IsTerminal returns whether the given stream (File) is attached to a TTY.
Types ¶
type StandardStreamsHandler ¶
type StandardStreamsHandler struct {
// contains filtered or unexported fields
}
func NewStandardStreamsHandler ¶
func NewStandardStreamsHandler() *StandardStreamsHandler
NewStandardStreamsHandler is a convenience function for constructing a new handler which sends to STDOUT/STDERR. If the output is sent to a TTY, the format is formatter.CONSOLE_COLOR_FORMAT. Otherwise it is formatter.CONSOLE_NOCOLOR_FORMAT. The only difference between the two are the use of color escape codes.
type WriterHandler ¶
WriterHandler is responsible for converting an event into text using a template, and then sending that text to an io.Writer.
func Append ¶
Append constructs a new WriterHandler which appends to the file at the given path, creating it if necessary. templateString must be a template supported by the sawmill/event/formatter package. If the templateString is empty, the WriterHandler will use sawmill/event/formatter.SIMPLE_FORMAT.
func New ¶
func New(output io.Writer, templateString string) (*WriterHandler, error)
New constructs a new WriterHandler handler. templateString must be a template supported by the sawmill/event/formatter package. If the templateString is empty, the WriterHandler will use sawmill/event/formatter.SIMPLE_FORMAT.