log

package
v0.0.0-...-8e53d61 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfoLevelSecurity  = "info"
	DebugLevelSecurity = "debug"
	WarnLevelSecurity  = "warn"
	ErrorLevelSecurity = "error"
)

The following is Level security definitions.

Variables

This section is empty.

Functions

func IsTerminal

func IsTerminal() bool

IsTerminal returns true if the given file descriptor is a terminal.

func NewContext

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

NewContext returns a new context with the given logger.

func ToKlogLevel

func ToKlogLevel(level Level) int

ToKlogLevel maps the current logging level to a Klog level integer

func ToLogSeverityLevel

func ToLogSeverityLevel(level Level) string

ToLogSeverityLevel maps the current logging level to a severity level string

Types

type DurationFormat

type DurationFormat struct {
	Nanosecond int64  `json:"nanosecond"`
	Human      string `json:"human"`
}

DurationFormat is the format used to print time.Duration in both nanosecond and string.

type Level

type Level = slog.Level

Level is the logging level.

const (
	LevelDebug Level = slog.LevelDebug
	LevelInfo  Level = slog.LevelInfo
	LevelWarn  Level = slog.LevelWarn
	LevelError Level = slog.LevelError
)

The following is Level definitions copied from slog.

func ParseLevel

func ParseLevel(s string) (l Level, err error)

ParseLevel parses a level string.

type Logger

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

Logger is a wrapper around slog.Handler.

func Entry

func Entry(ctx context.Context) *Logger

FromContext returns the Logger associated with ctx, or the default logger.

func InitFlags

func InitFlags(ctx context.Context, flags *pflag.FlagSet) (context.Context, *Logger)

InitFlags initializes the flags for the log.

func NewLogger

func NewLogger(w io.Writer, level Level) *Logger

NewLogger returns a new Logger that writes to w.

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs a debug message.

func (*Logger) Error

func (l *Logger) Error(msg string, err error, args ...any)

Error logs an error message.

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs an informational message.

func (*Logger) Level

func (l *Logger) Level() Level

Level returns

func (*Logger) Log

func (l *Logger) Log(level Level, msg string, args ...any)

Log logs a message with the given level.

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs a warning message.

func (*Logger) With

func (l *Logger) With(args ...any) *Logger

With returns a new Logger that includes the given arguments.

func (*Logger) WithGroup

func (l *Logger) WithGroup(name string) *Logger

WithGroup returns a new Logger that starts a group. The keys of all attributes added to the Logger will be qualified by the given name.

Jump to

Keyboard shortcuts

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