log

package
v0.4.2-98-gf5f5c1a Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: BSD-3-Clause Imports: 13 Imported by: 5

Documentation

Overview

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file except in compliance with the License.

SPDX-License-Identifier: MIT Copyright (c) 2017, Denis Parchenko. Copyright (c) 2022, Unikraft GmbH. All rights reserved.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file expect in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file expect in compliance with the License.

Index

Constants

View Source
const Format = "2006-01-02 15:04:05"

Variables

View Source
var (
	// G is an alias for FromContext.
	//
	// We may want to define this locally to a package to get package tagged log
	// messages.
	G = FromContext

	// L is the global logger.
	L = logrus.StandardLogger()
)

Functions

func FromContext added in v0.2.0

func FromContext(ctx context.Context) *logrus.Logger

FromContext returns the logger kraftkit in the context, or an inert logger that will not log anything.

func Levels added in v0.2.0

func Levels() map[string]logrus.Level

Levels returns a map of log level string names to their constant equivalent.

func LoggerTypeToString added in v0.2.0

func LoggerTypeToString(t LoggerType) string

func WithLogger added in v0.2.0

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

WithLogger returns a new context with the provided logger. Use in combination with logger.WithField(s) for great effect.

Types

type ColorScheme added in v0.2.0

type ColorScheme struct {
	InfoLevel  func(string) string
	WarnLevel  func(string) string
	ErrorLevel func(string) string
	FatalLevel func(string) string
	PanicLevel func(string) string
	DebugLevel func(string) string
	TraceLevel func(string) string
	Prefix     func(string) string
	Timestamp  func(string) string
}

type Logger

type Logger interface {
	Trace(a ...interface{})
	Tracef(format string, a ...interface{})
	Debug(a ...interface{})
	Debugf(format string, a ...interface{})
	Info(a ...interface{})
	Infof(format string, a ...interface{})
	Warn(a ...interface{})
	Warnf(format string, a ...interface{})
	Warning(a ...interface{})
	Warningf(format string, a ...interface{})
	Error(a ...interface{})
	Errorf(format string, a ...interface{})
	Fatal(a ...interface{})
	Fatalf(format string, a ...interface{})
	SetOutput(w io.Writer)

	// Clone provides a semantic copy of the current instance of the Logger such
	// that it can be used independently but with the same configuration.  This
	// may useful for sub-processes.
	Clone() Logger

	// Output returns the io.Writer used in the Logger's underlying implementation
	Output() io.Writer

	// Level returns the current log level
	Level() string
}

type LoggerType added in v0.2.0

type LoggerType uint

LoggerType controls how log statements are output

const (
	QUIET LoggerType = iota
	BASIC
	FANCY
	JSON
)

Logger types

func LoggerTypeFromString added in v0.2.0

func LoggerTypeFromString(name string) LoggerType

type TextFormatter added in v0.2.0

type TextFormatter struct {
	// Set to true to bypass checking for a TTY before outputting colors.
	ForceColors bool

	// Force disabling colors. For a TTY colors are enabled by default.
	DisableColors bool

	// Force formatted layout, even for non-TTY output.
	ForceFormatting bool

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool

	// Enable logging the full timestamp when a TTY is attached instead of just
	// the time passed since beginning of execution.
	FullTimestamp bool

	// Timestamp format to use for display when a full timestamp is printed.
	TimestampFormat string

	// The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting bool

	// Wrap empty fields in quotes if true.
	QuoteEmptyFields bool

	// Can be set to the override the default quoting character "
	// with something else. For example: ', or `.
	QuoteCharacter string

	// Pad msg field with spaces on the right for display.
	// The value for this parameter will be the size of padding.
	// Its default value is zero, which means no padding will be applied for msg.
	SpacePadding int

	sync.Once
	// contains filtered or unexported fields
}

func (*TextFormatter) Format added in v0.2.0

func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error)

func (*TextFormatter) SetColorScheme added in v0.2.0

func (f *TextFormatter) SetColorScheme(colorScheme *ColorScheme)

Jump to

Keyboard shortcuts

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