writer

package
v0.0.0-...-e2451da Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2015 License: MIT Imports: 8 Imported by: 4

README

The writer handler package is responsible for writing events to standard IO streams (io.Writer).

There are a few convenience functions for constructing handlers which write to STDOUT/STDERR and appending to normal files.

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"})

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

func IsTerminal(stream interface {
	Fd() uintptr
}) bool

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.

func (*StandardStreamsHandler) Event

func (handler *StandardStreamsHandler) Event(logEvent *event.Event) error

Event accepts an event and sends it to the appropriate output stream based on the event's level. If the level is warning or higher, it is sent to STDERR. Otherwise it is sent to STDOUT.

type WriterHandler

type WriterHandler struct {
	Output   io.Writer
	Template *template.Template
}

WriterHandler is responsible for converting an event into text using a template, and then sending that text to an io.Writer.

func Append

func Append(path string, mode os.FileMode, templateString string) (*WriterHandler, error)

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.

func (*WriterHandler) Event

func (handler *WriterHandler) Event(logEvent *event.Event) error

Event accepts an event, formats it, and writes it to the WriterHandler's Output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL