logger

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 6 Imported by: 19

Documentation

Overview

Package logger provides methods for logging with different levels.

Index

Constants

View Source
const (
	Ldate         = 1 << iota             // the date in the local time zone: 2009/01/23
	Ltime                                 // the time in the local time zone: 01:23:23
	Lmicroseconds                         // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                             // full file name and line number: /a/b/c/d.go:23
	Lshortfile                            // final file name element and line number: d.go:23. overrides Llongfile
	LUTC                                  // if Ldate or Ltime is set, use UTC rather than the local time zone
	Lmsgprefix                            // move the "prefix" from the beginning of the line to before the message
	LstdFlags     = Ldate | Lmicroseconds // initial values for the standard logger
)

Copied from Go log so callers don't need to also import log.

Variables

This section is empty.

Functions

func Debugf

func Debugf(ctx context.Context, format string, a ...interface{})

func Errorf

func Errorf(ctx context.Context, format string, a ...interface{})

func Fatalf

func Fatalf(ctx context.Context, format string, a ...interface{})

func Infof

func Infof(ctx context.Context, format string, a ...interface{})

func Logf

func Logf(ctx context.Context, logLevel LogLevel, format string, a ...interface{})

func Tracef

func Tracef(ctx context.Context, format string, a ...interface{})

func Warningf

func Warningf(ctx context.Context, format string, a ...interface{})

func WithLogger

func WithLogger(ctx context.Context, logger *Logger) context.Context

WithLogger returns the context with its logger set as the provided Logger.

Types

type LogLevel

type LogLevel int

LogLevel represents different levels for logging depending on the amount of detail wanted.

const (
	NoLogLevel LogLevel = iota
	FatalLevel
	ErrorLevel
	WarningLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

func (*LogLevel) Set

func (l *LogLevel) Set(s string) error

Set sets the LogLevel based on its string value.

func (*LogLevel) String

func (l *LogLevel) String() string

String returns the string representation of the LogLevel, or an empty string if the LogLevel has no string representation specified.

type Logger

type Logger struct {
	LoggerLevel LogLevel
	// contains filtered or unexported fields
}

Logger represents a specific LogLevel with a specified color and prefix.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) *Logger

LoggerFromContext returns the context logger if configured, otherwise nil.

func NewLogger

func NewLogger(loggerLevel LogLevel, color color.Color, outWriter, errWriter io.Writer, prefix interface{}) *Logger

NewLogger creates a new logger instance. The loggerLevel variable sets the log level for the logger. The color variable specifies the visual color of displayed log output. The outWriter and errWriter variables set the destination to which non-error and error data will be written. The prefix appears on the same line directly preceding any log data. It should be thread-safe to format this value.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, a ...interface{})

Debugf logs the string if the logger is at least DebugLevel.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, a ...interface{})

Errorf logs the string if the logger is at least ErrorLevel.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, a ...interface{})

Fatalf logs the string if the logger is at least FatalLevel.

func (*Logger) Infof

func (l *Logger) Infof(format string, a ...interface{})

Infof logs the string if the logger is at least InfoLevel.

func (*Logger) SetFlags

func (l *Logger) SetFlags(flags int)

func (*Logger) Tracef

func (l *Logger) Tracef(format string, a ...interface{})

Tracef logs the string if the logger is at least TraceLevel.

func (*Logger) Warningf

func (l *Logger) Warningf(format string, a ...interface{})

Warningf logs the string if the logger is at least WarningLevel.

Jump to

Keyboard shortcuts

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