package module
Version: v0.0.0-...-0bcc6e3 Latest Latest

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

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 2




View Source
const MinimumMaxLogSizeThreshold = 100

MaxLogSize values below this threshold are effectively ignored

View Source
const NoErrorCode = 0


This section is empty.


func FormatLog

func FormatLog(log *Log) string

func FormatLogWithTimezone

func FormatLogWithTimezone(log *Log) string

func GetFormatLogFunc

func GetFormatLogFunc() func(log *Log) string

func IgnoreThisFilenameToo

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 SetFormatLogFunc

func SetFormatLogFunc(f func(log *Log) string)

func SetMaxLogSize

func SetMaxLogSize(size int)

func TurboLevelFilter

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


type Appender

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

type Context

type Context struct {
	// contains filtered or unexported fields

func NewContext

func NewContext() *Context

func (*Context) Add

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

func (*Context) Get

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

func (*Context) Keys

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

func (*Context) Len

func (c *Context) Len() int

func (*Context) Remove

func (c *Context) Remove(key string)

type ErrorCode

type ErrorCode uint8

type ErrorWithCode

type ErrorWithCode struct {
	ErrCode ErrorCode
	Err     error

func (ErrorWithCode) Error

func (e ErrorWithCode) Error() string

type FileAppender

type FileAppender struct {

func DevNullAppender

func DevNullAppender() (*FileAppender, error)

func StdErrAppender

func StdErrAppender() *FileAppender

func StdOutAppender

func StdOutAppender() *FileAppender

func (FileAppender) Append

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

func (FileAppender) Flush

func (self FileAppender) Flush() error

type Filter

type Filter func(log *Log) bool

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

type FilterAppender

type FilterAppender struct {
	Appender Appender
	Filter   Filter

func LevelFilter

func LevelFilter(threshold Level, appender Appender) *FilterAppender

func (*FilterAppender) Append

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

func (*FilterAppender) Flush

func (self *FilterAppender) Flush() error

type Level

type Level uint8
const (
	TRACE Level = iota

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

func NewLevel

func NewLevel(levelStr string) (Level, error)

func (Level) String

func (self Level) String() string

func (Level) Type

func (self Level) Type() string

type Log

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

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

func SimpleLogStrippingDirs

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

func (*Log) Message

func (self *Log) Message() string

type Logger

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

func (*Logger) Errorf

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

func (*Logger) ErrorfWithContext

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

func (*Logger) ErrorfWithErrorCodeAndContext

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

func (*Logger) Flush

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

func (*Logger) Logf

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

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

func (*Logger) LogfWithErrorCodeAndContext

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

func (*Logger) Stackf

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

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

func (*Logger) StackfWithErrorCodeAndContext

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

type StackError

type StackError struct {
	Message    string
	Stacktrace []string

func NewStackError

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

func (*StackError) Error

func (self *StackError) Error() string

type StringAppender

type StringAppender struct {

func NewStringAppender

func NewStringAppender(buffer *bytes.Buffer) *StringAppender

func (StringAppender) Append

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

func (StringAppender) Flush

func (self StringAppender) Flush() error

type StringWriter

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

type TurboFilter

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

type UnknownLevelError struct {
	// contains filtered or unexported fields

func (UnknownLevelError) Error

func (self UnknownLevelError) Error() string

Jump to

Keyboard shortcuts

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