logger

package
v1.38.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultPrefix = "instana: "

DefaultPrefix is the default log prefix used by Logger

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level uint8

Level defines the minimum logging level for logger.Log

const (
	ErrorLevel Level = iota
	WarnLevel
	InfoLevel
	DebugLevel
)

Valid log levels to be used with (*logger.Logger).SetLevel()

func (Level) Less added in v1.37.0

func (lvl Level) Less(other Level) bool

Less returns whether the log level is less than the given one in logical order: ErrorLevel > WarnLevel > InfoLevel > DebugLevel

func (Level) String

func (lvl Level) String() string

String returns the log line label for this level

type Logger

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

Logger is a configurable leveled logger used by Instana's Go sensor. It follows the same interface as github.com/sirupsen/logrus.Logger and go.uber.org/zap.SugaredLogger

func New

func New(printer Printer) *Logger

New initializes a new instance of Logger that uses provided printer as a backend to output the log messages. The stdlib log.Logger satisfies logger.Printer interface:

logger := logger.New(logger.WarnLevel, log.New(os.Stderr, "instana:", log.LstdFlags))
logger.SetLevel(logger.WarnLevel)

logger.Debug("this is a debug message") // won't be printed
logger.Error("this is an  message") // ... while this one will

In case there is no printer provided, logger.Logger will use a new instance of log.Logger initialized with log.Lstdflags that writes to os.Stderr:

log.New(os.Stderr, "", log.Lstdflags)

The default logging level for a new logger instance is logger.ErrorLevel.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug appends a debug message to the log

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error appends an error message to the log

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info appends an info message to the log

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel changes the log level for this logger instance. In case there is an INSTANA_DEBUG env variable set, the provided log level will be overridden with DebugLevel.

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(prefix string)

SetPrefix sets the label that will be used as a prefix for each log line

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

Warn appends a warning message to the log

type Printer

type Printer interface {
	Print(a ...interface{})
}

Printer is used by logger.Log instance to print out a log message

Jump to

Keyboard shortcuts

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