log

package
v4.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package log output logged entries to respective logging hooks

Package log provide the logging interfaces

Index

Constants

View Source
const (

	// CsiRequestID use to mark requestId for log printer
	CsiRequestID key = "csi.requestid"

	// TagNameKey use to mark tag name key
	TagNameKey key = "csi.tag"

	// TagName use to mark tag for log printer
	TagName = "tag"
)

Variables

This section is empty.

Functions

func Close

func Close()

Close ensures closing output stream

func Debugf

func Debugf(format string, args ...interface{})

Debugf ensures output of formatted debug logs

func Debugln

func Debugln(args ...interface{})

Debugln ensures output of Debug logs

func EnsureGRPCContext

func EnsureGRPCContext(ctx context.Context, req interface{},
	info *grpc.UnaryServerInfo,
	handler grpc.UnaryHandler) (interface{}, error)

EnsureGRPCContext ensures adding request id in incoming context

func Errorf

func Errorf(format string, args ...interface{})

Errorf ensures output of formatted error logs

func Errorln

func Errorln(args ...interface{})

Errorln ensures output of error logs

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf ensures output of formatted fatal logs

func Fatalln

func Fatalln(args ...interface{})

Fatalln ensures output of fatal logs

func FilteredLog

func FilteredLog(ctx context.Context, isSkip, isDebug bool, msg string)

FilteredLog will not print the logs that need to be filtered, and the log level will be as required.

func Flush

func Flush()

Flush ensures to commit current content of logging stream

func Infof

func Infof(format string, args ...interface{})

Infof ensures output of formatted info logs

func Infoln

func Infoln(args ...interface{})

Infoln ensures output of info logs

func InitLogging

func InitLogging(req *Config) error

InitLogging configures logging. Logs are written to a log file or stdout/stderr. Since logrus doesn't support multiple writers, each log stream is implemented as a hook.

func MockInitLogging

func MockInitLogging(logName string)

MockInitLogging mock init the logging service

func MockStopLogging

func MockStopLogging(logName string)

MockStopLogging mock stop the logging service

func SetRequestInfo

func SetRequestInfo(ctx context.Context) (context.Context, error)

SetRequestInfo used to set the context with value

func SetRequestInfoWithTag

func SetRequestInfoWithTag(ctx context.Context, tag string) (context.Context, error)

SetRequestInfoWithTag set request tag

func Warningf

func Warningf(format string, args ...interface{})

Warningf ensures output of formatted warning logs

func Warningln

func Warningln(args ...interface{})

Warningln ensures output of warning logs

Types

type Config

type Config struct {
	LogName       string
	LogFileSize   string
	LoggingModule string
	LogLevel      string
	LogFileDir    string
	MaxBackups    uint
}

Config use to init the logging service

type ConsoleHook

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

ConsoleHook sends log entries to stdout/stderr.

func (*ConsoleHook) Fire

func (hook *ConsoleHook) Fire(entry *logrus.Entry) error

Fire ensure logging of respective log entries

func (*ConsoleHook) Levels

func (hook *ConsoleHook) Levels() []logrus.Level

Levels returns all supported levels

type FileHook

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

FileHook sends log entries to a file.

func (*FileHook) Fire

func (hook *FileHook) Fire(entry *logrus.Entry) error

Fire ensure logging of respective log entries

func (*FileHook) Levels

func (hook *FileHook) Levels() []logrus.Level

Levels returns all supported levels

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})

	Debugln(args ...interface{})

	Infof(format string, args ...interface{})

	Infoln(args ...interface{})

	Warningf(format string, args ...interface{})

	Warningln(args ...interface{})

	Errorf(format string, args ...interface{})

	Errorln(args ...interface{})

	Fatalf(format string, args ...interface{})

	Fatalln(args ...interface{})
}

Logger exposes logging functionality

func AddContext

func AddContext(ctx context.Context) Logger

AddContext ensures appending context info in log

type LoggingInterface

type LoggingInterface interface {
	Logger

	AddContext(ctx context.Context) Logger
	// contains filtered or unexported methods
}

LoggingInterface is an interface exposes logging functionality

type PlainTextFormatter

type PlainTextFormatter struct {
	// TimestampFormat to use for display when a full timestamp is printed
	TimestampFormat string
	// contains filtered or unexported fields
}

PlainTextFormatter is a formatter to ensure formatted logging output

func (*PlainTextFormatter) Format

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

Format ensure unified and formatted logging output

Jump to

Keyboard shortcuts

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