log

package
v0.0.1-test Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// top 7 calls in the stack are within logger
	DefaultCallerDepth = 7
	CallerContextKey   = "caller"
)

Variables

This section is empty.

Functions

func Caller

func Caller(depth int) gokitlog.Valuer

Caller proxies go-kit/log Caller and returns a Valuer function that returns a file and line from a specified depth in the callstack

func Close

func Close() error

this is for file logger only

func IncDBCallCounter

func IncDBCallCounter(ctx context.Context) context.Context

IncDBCallCounter increments the database counter on the context.

func InitCounter

func InitCounter(ctx context.Context) context.Context

InitCounter creates a pointer on the context that can be incremented later

func ReadLoggingConfig

func ReadLoggingConfig(modes []string, logsPath string, cfg *ini.File) error

func RegisterContextualLogProvider

func RegisterContextualLogProvider(mw ContextualLogProviderFunc)

RegisterContextualLogProvider registers a ContextualLogProviderFunc that will be used to provide context when Logger.FromContext is called.

func Reload

func Reload() error

Reload reloads all loggers.

func Stack

func Stack(skip int) string

func StackCaller

func StackCaller(skip int) gokitlog.Valuer

StackCaller returns a go-kit Valuer function that returns the stack trace from the place it is called. Argument `skip` allows skipping top n lines from the stack.

func TotalDBCallCount

func TotalDBCallCount(ctx context.Context) int64

TotalDBCallCount returns the total number of requests for the context

Types

type ConcreteLogger

type ConcreteLogger struct {
	gokitlog.SwapLogger
	// contains filtered or unexported fields
}

func New

func New(ctx ...interface{}) *ConcreteLogger

New creates a new logger. First ctx argument is expected to be the name of the logger. Note: For a contextual logger, i.e. a logger with a shared name plus additional contextual information, you must use the Logger interface New method for it to work as expected. Example creating a shared logger:

requestLogger := log.New("request-logger")

Example creating a contextual logger:

contextualLogger := requestLogger.New("username", "user123")

func NewNopLogger

func NewNopLogger() *ConcreteLogger

NewNopLogger returns a logger that doesn't do anything.

func WithPrefix

func WithPrefix(ctxLogger *ConcreteLogger, ctx ...interface{}) *ConcreteLogger

WithPrefix adds context that will be added to the log message

func WithSuffix

func WithSuffix(ctxLogger *ConcreteLogger, ctx ...interface{}) *ConcreteLogger

WithSuffix adds context that will be appended at the end of the log message

func (*ConcreteLogger) Debug

func (cl *ConcreteLogger) Debug(msg string, args ...interface{})

func (*ConcreteLogger) Error

func (cl *ConcreteLogger) Error(msg string, args ...interface{})

func (*ConcreteLogger) FromContext

func (cl *ConcreteLogger) FromContext(ctx context.Context) Logger

func (ConcreteLogger) GetLogger

func (cl ConcreteLogger) GetLogger() gokitlog.Logger

func (*ConcreteLogger) Info

func (cl *ConcreteLogger) Info(msg string, args ...interface{})

func (*ConcreteLogger) Log

func (cl *ConcreteLogger) Log(ctx ...interface{}) error

func (*ConcreteLogger) New

func (cl *ConcreteLogger) New(ctx ...interface{}) *ConcreteLogger

func (*ConcreteLogger) Warn

func (cl *ConcreteLogger) Warn(msg string, args ...interface{})

type ContextualLogProviderFunc

type ContextualLogProviderFunc func(ctx context.Context) ([]interface{}, bool)

ContextualLogProviderFunc contextual log provider function definition.

type DisposableHandler

type DisposableHandler interface {
	Close() error
}

type FileLogWriter

type FileLogWriter struct {
	Format   Formatedlogger
	Filename string
	Maxlines int

	// Rotate at size
	Maxsize int

	// Rotate daily
	Daily   bool
	Maxdays int64

	Rotate bool

	sync.Mutex
	// contains filtered or unexported fields
}

FileLogWriter implements LoggerInterface. It writes messages by lines limit, file size limit, or time frequency.

func NewFileWriter

func NewFileWriter() *FileLogWriter

create a FileLogWriter returning as LoggerInterface.

func (*FileLogWriter) Close

func (w *FileLogWriter) Close() error

destroy file logger, close file writer.

func (*FileLogWriter) DoRotate

func (w *FileLogWriter) DoRotate() error

DoRotate means it need to write file in new file. new file name like xx.log.2013-01-01.2

func (*FileLogWriter) Flush

func (w *FileLogWriter) Flush()

flush file logger. there are no buffering messages in file logger in memory. flush file means sync file from disk.

func (*FileLogWriter) Init

func (w *FileLogWriter) Init() error

func (*FileLogWriter) Log

func (w *FileLogWriter) Log(keyvals ...interface{}) error

func (*FileLogWriter) Reload

func (w *FileLogWriter) Reload() error

Reload file logger

func (*FileLogWriter) StartLogger

func (w *FileLogWriter) StartLogger() error

start file logger. create log file and set to locker-inside file writer.

func (*FileLogWriter) Write

func (w *FileLogWriter) Write(b []byte) (int, error)

write to os.File.

type Formatedlogger

type Formatedlogger func(w io.Writer) gokitlog.Logger

type Logger

type Logger interface {
	// New returns a new contextual Logger that has this logger's context plus the given context.
	New(ctx ...interface{}) *ConcreteLogger

	Log(keyvals ...interface{}) error

	// Debug logs a message with debug level and key/value pairs, if any.
	Debug(msg string, ctx ...interface{})

	// Info logs a message with info level and key/value pairs, if any.
	Info(msg string, ctx ...interface{})

	// Warn logs a message with warning level and key/value pairs, if any.
	Warn(msg string, ctx ...interface{})

	// Error logs a message with error level and key/value pairs, if any.
	Error(msg string, ctx ...interface{})

	// FromContext returns a new contextual Logger that has this logger's context plus the given context.
	FromContext(ctx context.Context) Logger
}

type Lvl

type Lvl int
const (
	LvlCrit Lvl = iota
	LvlError
	LvlWarn
	LvlInfo
	LvlDebug
)

type ReloadableHandler

type ReloadableHandler interface {
	Reload() error
}

type SysLogHandler

type SysLogHandler struct {
	Network  string
	Address  string
	Facility string
	Tag      string
	Format   Formatedlogger
	// contains filtered or unexported fields
}

func NewSyslog

func NewSyslog(sec *ini.Section, format Formatedlogger) *SysLogHandler

func (*SysLogHandler) Close

func (sw *SysLogHandler) Close() error

func (*SysLogHandler) Init

func (sw *SysLogHandler) Init() error

func (*SysLogHandler) Log

func (sw *SysLogHandler) Log(keyvals ...interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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