slogger

package
v0.0.0-...-0df0820 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DevNullAppender

func DevNullAppender() (send.Sender, error)

DevNullAppender returns a configured stream logger Sender instance that writes messages to dev null.

func FormatLog

func FormatLog(log *Log) string

FormatLog provides compatibility with the original slogger implementation.

func LevelFilter

func LevelFilter(threshold Level, sender send.Sender) send.Sender

LevelFilter provides compatibility with a legacy slogger implementation that filgered messages lower than the specified priority. This implementation simply sets the threshold level on that sender and returns it.

func NewAppenderSender

func NewAppenderSender(name string, a Appender) send.Sender

NewAppenderSender implements the send.Sender interface, which allows it to be used as a grip backend, but the it's mode of action is to use a slogger.Appender. This allows using the grip package, either via the slogger interface or the normal grip Jouernaler interface, while continuing to use existing slogger code.

func NewStringAppender

func NewStringAppender(buffer *bytes.Buffer) send.Sender

NewStringAppender wraps a bytes.Buffer and provides an send.Sender/Appender interface that writes log messages to that buffer.

func StdErrAppender

func StdErrAppender() send.Sender

StdErrAppender returns a configured stream logger Sender instance that writes messages to standard error.

func StdOutAppender

func StdOutAppender() send.Sender

StdOutAppender returns a configured stream logger Sender instance that writes messages to standard output.

func WrapAppender

func WrapAppender(a Appender) send.Sender

WrapAppender takes an Appender instance and returns a send.Sender instance that wraps it. The name defaults to the name of the process (argc).

Types

type Appender

type Appender interface {
	Append(log *Log) error
}

Appender is the slogger equivalent of a send.Sender, and this provides the same public interface for Appenders, in terms of Grip's senders.

type Level

type Level uint8

Level represents slogger's level types. In the original implementation there are four levels and an "OFF" value.

const (
	OFF Level = iota
	DEBUG
	INFO
	WARN
	ERROR
)

slogger has its own system of priorities/log levels. These constants represent those levels, and the Level type can be converted to grip level.Priority values.

func (Level) Priority

func (l Level) Priority() level.Priority

Priority returns grip's native level.Priority for a slogger.Level.

func (Level) String

func (l Level) String() string

type Log

type Log struct {
	Prefix    string    `bson:"prefix,omitempty" json:"prefix,omitempty" yaml:"prefix,omitempty"`
	Level     Level     `bson:"level" json:"level" yaml:"level"`
	Filename  string    `bson:"filename" json:"filename" yaml:"filename"`
	Line      int       `bson:"line" json:"line" yaml:"line"`
	Timestamp time.Time `bson:"timestamp" json:"timestamp" yaml:"timestamp"`
	Output    string    `bson:"message,omitempty" json:"message,omitempty" yaml:"message,omitempty"`
	// contains filtered or unexported fields
}

Log is a representation of a logging event, which matches the structure and interface of the original slogger Log type. Additionally implements grip's "message.Composer" interface for use with other logging mechanisms.

Note that the String() method, which Sender's use to format the output of the log lines includes timestamp and component (name/prefix) information.

func NewLog

func NewLog(m message.Composer) *Log

NewLog takes a message.Composer object and returns a slogger.Log instance (which also implements message.Composer). This method records its callsite, so you ought to call this method directly.

func NewPrefixedLog

func NewPrefixedLog(prefix string, m message.Composer) *Log

NewPrefixedLog allows you to construct a slogger.Log message from a message composer, while specifying a prefix.

func (*Log) Annotate

func (l *Log) Annotate(k string, v interface{}) error

func (*Log) Loggable

func (l *Log) Loggable() bool

func (*Log) Message

func (l *Log) Message() string

Message returns the formatted log message.

func (*Log) Priority

func (l *Log) Priority() level.Priority

func (*Log) Raw

func (l *Log) Raw() interface{}

func (*Log) SetPriority

func (l *Log) SetPriority(lvl level.Priority) error

func (*Log) String

func (l *Log) String() string

type Logger

type Logger struct {
	Name      string
	Appenders []send.Sender
}

Logger is a type that represents a single log instance. This is analogous to the original slogger's Logger type; however, the Appender field stores a slice of sned.Senders rather than slogger.Appenders; however, the Appender type is defined in the new slogger, and the NewAppenderSender and WrapAppender functions afford the conversion.

func (*Logger) Errorf

func (l *Logger) Errorf(level Level, messageFmt string, args ...interface{}) error

Errorf logs and returns its message as an error.

Log and return a formatted error string. Example:i

if whatIsExpected != whatIsReturned {
    return slogger.Errorf(slogger.WARN, "Unexpected return value. Expected: %v Received: %v",
        whatIsExpected, whatIsReturned)
}

func (*Logger) Logf

func (l *Logger) Logf(level Level, messageFmt string, args ...interface{}) (*Log, []error)

Logf logs a message and a level to a logger instance. This returns a pointer to a Log and a slice of errors that were gathered from every Appender (nil errors included).

In this implementation, Logf will never return an error. This part of the type definition was retained for backwards compatibility

func (*Logger) Stackf

func (l *Logger) Stackf(level Level, stackErr error, messageFmt string, args ...interface{}) (*Log, []error)

Stackf is designed to work in tandem with `NewStackError`. This function is similar to `Logf`, but takes a `stackErr` parameter. `stackErr` is expected to be of type StackError, but does not have to be.

In this implementation, Logf will never return an error. This part of the type definition was retained for backwards compatibility.

An additional difference is that the new implementation, will not log if the error is nil, and the previous implementation would.

type SenderAppender

type SenderAppender struct {
	send.Sender
}

SenderAppender is a shim that implements the Appender interface around any arbitrary sender instance.

func (SenderAppender) Append

func (s SenderAppender) Append(log *Log) error

Append sends a log message. This method *always* returns nil.

type StackError

type StackError struct {
	message.Composer
	Stacktrace []string
	// contains filtered or unexported fields
}

StackError is a grip re implementation of a type from legacy slogger. It combines a stacktrace of the call site of the logged message and a message composer. StackError also implements the error interface. The composer's "loggability" is derived from the embedded composer.

func NewStackError

func NewStackError(messageFmt string, args ...interface{}) *StackError

NewStackError produces a StackError object, collecting the stacktrace and building a Formatted message composer (e.g. fmt.Sprintf).

func (*StackError) Error

func (s *StackError) Error() string

Error returns the resolved error message for the StackError instance and satisfies the error interface.

func (*StackError) Raw

func (s *StackError) Raw() interface{}

Raw produces a structure that contains the mesage, stacktrace, and raw metadata from the embedded composer for use by some logging backends.

func (*StackError) String

func (s *StackError) String() string

String lazily resolves a message for the instance and caches that message internally.

Jump to

Keyboard shortcuts

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