slogger: github.com/mongodb/slogger/v2/slogger Index | Files | Directories

package slogger

import "github.com/mongodb/slogger/v2/slogger"

Index

Package Files

appender.go context.go filter.go logger.go

Constants

const NoErrorCode = 0

func FormatLog Uses

func FormatLog(log *Log) string

func IgnoreThisFilenameToo Uses

func IgnoreThisFilenameToo(fn string)

Add a file to the list of file names that slogger will skip when it identifies the source of a message. This is useful if you have a logging library built on top of slogger. If you IgnoreThisFilenameToo(...) on the files of that library, logging messages will be marked as coming from your code that calls your library, rather than from your library.

func TurboLevelFilter Uses

func TurboLevelFilter(threshold Level) func(Level, string, ...interface{}) bool

type Appender Uses

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

type Context Uses

type Context struct {
    // contains filtered or unexported fields
}

func NewContext Uses

func NewContext() *Context

func (*Context) Add Uses

func (c *Context) Add(key string, value interface{})

func (*Context) Get Uses

func (c *Context) Get(key string) (value interface{}, found bool)

func (*Context) Keys Uses

func (c *Context) Keys() []string

func (*Context) Len Uses

func (c *Context) Len() int

func (*Context) Remove Uses

func (c *Context) Remove(key string)

type ErrorCode Uses

type ErrorCode uint8

type ErrorWithCode Uses

type ErrorWithCode struct {
    ErrCode ErrorCode
    Err     error
}

func (ErrorWithCode) Error Uses

func (e ErrorWithCode) Error() string

type FileAppender Uses

type FileAppender struct {
    StringWriter
}

func DevNullAppender Uses

func DevNullAppender() (*FileAppender, error)

func StdErrAppender Uses

func StdErrAppender() *FileAppender

func StdOutAppender Uses

func StdOutAppender() *FileAppender

func (FileAppender) Append Uses

func (self FileAppender) Append(log *Log) error

func (FileAppender) Flush Uses

func (self FileAppender) Flush() error

type Filter Uses

type Filter func(log *Log) bool

Return true if the log should be passed to the underlying `Appender`

type FilterAppender Uses

type FilterAppender struct {
    Appender Appender
    Filter   Filter
}

func LevelFilter Uses

func LevelFilter(threshold Level, appender Appender) *FilterAppender

func (*FilterAppender) Append Uses

func (self *FilterAppender) Append(log *Log) error

func (*FilterAppender) Flush Uses

func (self *FilterAppender) Flush() error

type Level Uses

type Level uint8
const (
    DEBUG Level = iota
    INFO
    WARN
    ERROR
    FATAL
    OFF
)

The level is in an order such that the expressions `level < WARN`, `level >= INFO` have intuitive meaning.

func NewLevel Uses

func NewLevel(levelStr string) (Level, error)

func (Level) String Uses

func (self Level) String() string

func (Level) Type Uses

func (self Level) Type() string

type Log Uses

type Log struct {
    Prefix     string
    Level      Level
    ErrorCode  ErrorCode
    Filename   string
    FuncName   string
    Line       int
    Timestamp  time.Time
    MessageFmt string
    Args       []interface{}
    Context    *Context
}

func SimpleLog Uses

func SimpleLog(prefix string, level Level, errorCode ErrorCode, callerSkip int, messageFmt string, args ...interface{}) *Log

func SimpleLogStrippingDirs Uses

func SimpleLogStrippingDirs(prefix string, level Level, errorCode ErrorCode, callerSkip int, numDirsToKeep int, messageFmt string, args ...interface{}) *Log

func (*Log) Message Uses

func (self *Log) Message() string

type Logger Uses

type Logger struct {
    Prefix       string
    Appenders    []Appender
    StripDirs    int
    TurboFilters []TurboFilter
}

func (*Logger) Errorf Uses

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

func (*Logger) ErrorfWithContext Uses

func (self *Logger) ErrorfWithContext(level Level, messageFmt string, context *Context, args ...interface{}) error

func (*Logger) ErrorfWithErrorCodeAndContext Uses

func (self *Logger) ErrorfWithErrorCodeAndContext(level Level, errorCode ErrorCode, messageFmt string, context *Context, args ...interface{}) error

func (*Logger) Flush Uses

func (self *Logger) Flush() (errors []error)

func (*Logger) Logf Uses

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

Log 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), or nil and an empty error slice if any turbo filter condition was not satisfied causing an early exit.

func (*Logger) LogfWithContext Uses

func (self *Logger) LogfWithContext(level Level, messageFmt string, context *Context, args ...interface{}) (*Log, []error)

func (*Logger) LogfWithErrorCodeAndContext Uses

func (self *Logger) LogfWithErrorCodeAndContext(level Level, errorCode ErrorCode, messageFmt string, context *Context, args ...interface{}) (*Log, []error)

func (*Logger) Stackf Uses

func (self *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.

func (*Logger) StackfWithContext Uses

func (self *Logger) StackfWithContext(level Level, stackErr error, messageFmt string, context *Context, args ...interface{}) (*Log, []error)

func (*Logger) StackfWithErrorCodeAndContext Uses

func (self *Logger) StackfWithErrorCodeAndContext(level Level, errorCode ErrorCode, stackErr error, messageFmt string, context *Context, args ...interface{}) (*Log, []error)

type StackError Uses

type StackError struct {
    Message    string
    Stacktrace []string
}

func NewStackError Uses

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

func (*StackError) Error Uses

func (self *StackError) Error() string

type StringAppender Uses

type StringAppender struct {
    *bytes.Buffer
}

func NewStringAppender Uses

func NewStringAppender(buffer *bytes.Buffer) *StringAppender

func (StringAppender) Append Uses

func (self StringAppender) Append(log *Log) error

func (StringAppender) Flush Uses

func (self StringAppender) Flush() error

type StringWriter Uses

type StringWriter interface {
    WriteString(s string) (ret int, err error)
    Sync() error
}

type TurboFilter Uses

type TurboFilter func(level Level, messageFmt string, args ...interface{}) bool

enables level-filtering before a Log entry is created, avoiding the runtime.Caller invocation return true if filter evaluation should continue

type UnknownLevelError Uses

type UnknownLevelError struct {
    // contains filtered or unexported fields
}

func (UnknownLevelError) Error Uses

func (self UnknownLevelError) Error() string

Directories

PathSynopsis
async_appender
queue
retaining_level_filter_appender
rolling_file_appender
test_util

Package slogger imports 7 packages (graph) and is imported by 4 packages. Updated 2017-04-29. Refresh now. Tools for package owners.