reader

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package reader contains a series of readers that can understand how an entry can be written to a destination. Plain will produce a one line entry to be written on the logs, like how nginx logs look like.

Index

Constants

View Source
const (
	// INFO is a log level.
	INFO = "info"
	// ERROR is a log level.
	ERROR = "error"
	// WARN is a log level.
	WARN = "warning"
)

Variables

View Source
var (
	// ErrNilTimestamp is returned when timestamp is and empty time.Time
	ErrNilTimestamp = errors.New("nil timestamp")

	// ErrEmptyMessage is returned when the message body is an empty string.
	ErrEmptyMessage = errors.New("empty message")

	// ErrTimestamp is returned when the timestamp is not valid.
	ErrTimestamp = errors.New("invalid timestamp")

	// ErrEmptyObject is retuned when the payload is an empty object.
	ErrEmptyObject = errors.New("empty object")

	// ErrCorruptedJSON is returned the payload is corrupted.
	ErrCorruptedJSON = errors.New("corrupted json")
)
View Source
var TimestampFormat = time.RFC3339

TimestampFormat is the default formatting defined for logs.

Functions

func GetReader

func GetReader(r io.Reader, logger internal.FieldLogger) (io.Reader, error)

GetReader tries to guess an appropriate reader from the input reader and returns it. It will fall back to Plain reader. It returns an error if there is no type or message are in the input or the message is empty.

Types

type Plain

type Plain struct {
	Kind      string
	Message   string
	Timestamp time.Time
	Logger    internal.FieldLogger
	// contains filtered or unexported fields
}

Plain implements the io.Reader interface and can read a json object and output a one line error message. For example:

{
    "type": "error",
    "timestamp": "2017-10-09 10:45:00",
    "message": "something happened",
}

Will become:

[2017-10-09 10:45:00] [ERROR] something happened

func (*Plain) Read

func (p *Plain) Read(b []byte) (int, error)

type TextFormatter added in v0.0.2

type TextFormatter struct {
	logrus.TextFormatter
}

TextFormatter is used for rendering a custom format. We need to put the time at the very beginning of the line.

func (*TextFormatter) Format added in v0.0.2

func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format will use the timestamp passed by the payload and injects it in the entry itself.

Jump to

Keyboard shortcuts

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