grip: Index | Files

package slogger

import ""


Package Files

appender.go appender_sender.go level.go log.go logger.go stack_error.go

func DevNullAppender Uses

func DevNullAppender() (send.Sender, error)

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

func FormatLog Uses

func FormatLog(log *Log) string

FormatLog provides compatibility with the original slogger implementation.

func LevelFilter Uses

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 Uses

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 Uses

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 Uses

func StdErrAppender() send.Sender

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

func StdOutAppender Uses

func StdOutAppender() send.Sender

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

func WrapAppender Uses

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).

type Appender Uses

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 Uses

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

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 Uses

func (l Level) Priority() level.Priority

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

func (Level) String Uses

func (l Level) String() string

type Log Uses

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 Uses

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 Uses

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 Uses

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

func (*Log) Loggable Uses

func (l *Log) Loggable() bool

func (*Log) Message Uses

func (l *Log) Message() string

Message returns the formatted log message.

func (*Log) Priority Uses

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

func (*Log) Raw Uses

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

func (*Log) SetPriority Uses

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

func (*Log) String Uses

func (l *Log) String() string

type Logger Uses

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 Uses

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 Uses

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 Uses

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 Uses

type SenderAppender struct {

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

func (SenderAppender) Append Uses

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

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

type StackError Uses

type StackError struct {
    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 Uses

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 Uses

func (s *StackError) Error() string

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

func (*StackError) Raw Uses

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 Uses

func (s *StackError) String() string

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

Package slogger imports 10 packages (graph) and is imported by 17 packages. Updated 2018-11-01. Refresh now. Tools for package owners.