log

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 8 Imported by: 76

README

go-log

Go-Log is a wrapper for go standard logger which allows to create custom log instances pointing to the same Stdout but different log levels and different runtime.Caller levels.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Constructor = NewLog(FileDepth(2))
View Source
var PrefixedStdLogger = Constructor.PrefixedLog(FileDepth(3))
View Source
var StdLogger = Constructor.Log(FileDepth(3))

Functions

func Debug

func Debug(message interface{}, params ...interface{})

Debug logs with DEBUG level using the standard logger.

func DebugContext

func DebugContext(ctx context.Context, message interface{}, params ...interface{})

DebugContext logs with DEBUG level with context and prefix using the standard logger.

func Error

func Error(message interface{}, params ...interface{})

Error logs with ERROR level using the standard logger.

func ErrorContext

func ErrorContext(ctx context.Context, message interface{}, params ...interface{})

ErrorContext logs with ERROR level with context and prefix using the standard logger.

func Fatal

func Fatal(message interface{}, params ...interface{})

Fatal logs with FATAL level using the standard logger.

func FatalContext

func FatalContext(ctx context.Context, message interface{}, params ...interface{})

FatalContext logs with FATAL level with context and prefix using the standard logger.

func Info

func Info(message interface{}, params ...interface{})

Info logs with INFO level using the standard logger.

func InfoContext

func InfoContext(ctx context.Context, message interface{}, params ...interface{})

InfoContext logs with INFO level with context and prefix using the standard logger.

func Trace

func Trace(message interface{}, params ...interface{})

Trace logs with TRACE level using the standard logger.

func TraceContext

func TraceContext(ctx context.Context, message interface{}, params ...interface{})

TraceContext logs with TRACE level with context and prefix using the standard logger.

func Warn

func Warn(message interface{}, params ...interface{})

Warn logs with WARN level using the standard logger.

func WarnContext

func WarnContext(ctx context.Context, message interface{}, params ...interface{})

WarnContext logs with WARN level with context and prefix using the standard logger.

func WithPrefix deprecated

func WithPrefix(p string, message interface{}) string

Deprecated: Do not use with the json logger.

WithPrefix appends the given prefix to the existing prefix.

Types

type Level

type Level string
const (
	FATAL Level = `FATAL`
	ERROR Level = `ERROR`
	WARN  Level = `WARN`
	INFO  Level = `INFO`
	DEBUG Level = `DEBUG`
	TRACE Level = `TRACE`
)

type Log

type Log interface {
	Log(...Option) Logger
	SimpleLog() SimpleLogger
	PrefixedLog(...Option) PrefixedLogger
}

func NewLog

func NewLog(options ...Option) Log

NewLog creates a new instance of the logger.

type Logger

type Logger interface {
	SimpleLogger
	NewLog(...Option) Logger
	NewPrefixedLog(opts ...Option) PrefixedLogger
	Fatal(message interface{}, params ...interface{})
	Error(message interface{}, params ...interface{})
	Warn(message interface{}, params ...interface{})
	Debug(message interface{}, params ...interface{})
	Info(message interface{}, params ...interface{})
	Trace(message interface{}, params ...interface{})
	FatalContext(ctx context.Context, message interface{}, params ...interface{})
	ErrorContext(ctx context.Context, message interface{}, params ...interface{})
	WarnContext(ctx context.Context, message interface{}, params ...interface{})
	DebugContext(ctx context.Context, message interface{}, params ...interface{})
	InfoContext(ctx context.Context, message interface{}, params ...interface{})
	TraceContext(ctx context.Context, message interface{}, params ...interface{})
}

func NewNoopLogger

func NewNoopLogger() Logger

type Option

type Option func(*logOptions)

Option represents a function that does one or more alterations to 'logOptions' inside the logger.

func FileDepth deprecated

func FileDepth(d int) Option

Deprecated: use WithSkipFrameCount instead.

FileDepth sets the frame count to skip when reading filepath, func path.

func Prefixed

func Prefixed(prefix string) Option

Prefixed appends the given prefix value to the existing prefix value.

func WithColors

func WithColors(enabled bool) Option

WithColors enables colours in log messages.

func WithCtxExtractor added in v1.1.0

func WithCtxExtractor(fn func(ctx context.Context) []interface{}) Option

WithCtxExtractor allows setting up of a function to extract values from the context.

func WithCtxTraceExtractor added in v1.2.0

func WithCtxTraceExtractor(fn func(ctx context.Context) string) Option

WithCtxTraceExtractor allows setting up of a function to extract trace from the context. Default value func(_ context.Context) string{return ""}

func WithFilePath

func WithFilePath(enabled bool) Option

WithFilePath sets whether the file path is logged or not.

func WithFuncPath added in v1.2.0

func WithFuncPath(enabled bool) Option

WithFilePath sets whether the file path is logged or not.

func WithLevel

func WithLevel(level Level) Option

WithLevel sets the log level.

The log level is used to determine which types of logs are logged depending on the precedence of the log level.

func WithOutput added in v1.2.0

func WithOutput(o Output) Option

WithOutput sets the output format for log entries.

func WithSkipFrameCount added in v1.2.0

func WithSkipFrameCount(c int) Option

WithSkipFrameCount sets the frame count to skip when reading filepath, func path.

func WithStdOut

func WithStdOut(w io.Writer) Option

WithStdOut sets the log writer.

type Output added in v1.2.0

type Output string
const (
	OutText Output = `text`
	OutJson Output = `json`
)

type PrefixedLogger

type PrefixedLogger interface {
	SimpleLogger
	NewLog(...Option) Logger
	NewPrefixedLog(opts ...Option) PrefixedLogger
	Fatal(prefix string, message interface{}, params ...interface{})
	Error(prefix string, message interface{}, params ...interface{})
	Warn(prefix string, message interface{}, params ...interface{})
	Debug(prefix string, message interface{}, params ...interface{})
	Info(prefix string, message interface{}, params ...interface{})
	Trace(prefix string, message interface{}, params ...interface{})
	FatalContext(ctx context.Context, prefix string, message interface{}, params ...interface{})
	ErrorContext(ctx context.Context, prefix string, message interface{}, params ...interface{})
	WarnContext(ctx context.Context, prefix string, message interface{}, params ...interface{})
	DebugContext(ctx context.Context, prefix string, message interface{}, params ...interface{})
	InfoContext(ctx context.Context, prefix string, message interface{}, params ...interface{})
	TraceContext(ctx context.Context, prefix string, message interface{}, params ...interface{})
}

func NewPrefixedNoopLogger

func NewPrefixedNoopLogger() PrefixedLogger

type SimpleLogger

type SimpleLogger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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