log

package
v1.5.8-rc2-feat-conf-mq Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var InvalidLoggerFormatType = errors.New("invalid LoggerFormatType type")
View Source
var InvalidLoggerOutputType = errors.New("invalid LoggerOutputType type")
View Source
var (
	JsonFormatter = &logrus.JSONFormatter{
		FieldMap: logrus.FieldMap{
			logrus.FieldKeyLevel: "@lv",
			logrus.FieldKeyTime:  "@ts",
			logrus.FieldKeyFunc:  "@fn",
			logrus.FieldKeyFile:  "@fl",
		},
		CallerPrettyfier: func(f *runtime.Frame) (fn string, file string) {
			return f.Function + " line:" + strconv.FormatInt(int64(f.Line), 10), ""
		},
		TimestampFormat: "20060102-150405.000Z07:00",
	}
)

Functions

func InstallPipeline

func InstallPipeline(output LoggerOutputType, format LoggerFormatType, exporter trace.SpanExporter) error

func KeyValues

func KeyValues(kvs ...interface{}) logrus.Fields

func WithLogger

func WithLogger(ctx context.Context, l Logger) context.Context

func WithLoggerContext added in v1.1.0

func WithLoggerContext(l Logger) contextx.WithContext

Types

type ClickhouseHook added in v1.4.6

type ClickhouseHook struct {
	CKEndpoint string
	// contains filtered or unexported fields
}

func (*ClickhouseHook) Fire added in v1.4.6

func (ck *ClickhouseHook) Fire(entry *logrus.Entry) error

func (*ClickhouseHook) Levels added in v1.4.6

func (ck *ClickhouseHook) Levels() []logrus.Level

type ErrIgnoreExporter

type ErrIgnoreExporter struct{ trace.SpanExporter }

func (*ErrIgnoreExporter) ExportSpans

func (e *ErrIgnoreExporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan) error

type Level

type Level uint32

Level type

const (
	// PanicLevel level, the highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel Level = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

func ParseLevel

func ParseLevel(lvl string) (Level, error)

ParseLevel takes a string level and returns the Logrus log level constant.

func (Level) LogrusLogLevel

func (lvl Level) LogrusLogLevel() logrus.Level

func (Level) MarshalText

func (lvl Level) MarshalText() ([]byte, error)

func (Level) String

func (lvl Level) String() string

func (*Level) UnmarshalText

func (lvl *Level) UnmarshalText(text []byte) error

type LevelSetter

type LevelSetter interface {
	SetLevel(lvl Level) Logger
}

type Log

type Log struct {
	Name         string
	Level        Level            `env:""`
	Output       LoggerOutputType `env:""`
	Format       LoggerFormatType
	CKEndpoint   string             `env:""`
	Exporter     trace.SpanExporter `env:"-"`
	ReportCaller bool
}

func (*Log) Init

func (l *Log) Init()

func (*Log) InitLogrus

func (l *Log) InitLogrus()

func (*Log) InitSpanLog

func (l *Log) InitSpanLog()

func (*Log) SetDefault

func (l *Log) SetDefault()

type Logger

type Logger interface {
	// Start to start span for tracing
	//
	// 	ctx log = log.Start(ctx, "SpanName")
	// 	defer log.End()
	//
	Start(context.Context, string, ...interface{}) (context.Context, Logger)
	// End to end span
	End()

	// WithValues key value pairs
	WithValues(keyAndValues ...interface{}) Logger

	Trace(msg string, args ...interface{})
	Debug(msg string, args ...interface{})
	Info(msg string, args ...interface{})
	Warn(err error)
	Error(err error)
	Fatal(err error)
	Panic(err error)
}
Example
ctx := WithLogger(context.Background(), Std())

l := FromContext(ctx).WithValues("k", "k")

l.Debug("test %d", 1)
l.Trace("test %d", 1)
l.Info("test %d", 1)
Output:

func Discard

func Discard() Logger

func FromContext

func FromContext(ctx context.Context) Logger

func Span

func Span(tracer string, s trace.Span) Logger

func SpanContext

func SpanContext(ctx context.Context, tracer string) (context.Context, Logger)

func Start

func Start(ctx context.Context, name string, kvs ...interface{}) (context.Context, Logger)

func Std

func Std() Logger

func StdContext

func StdContext(ctx context.Context) (context.Context, Logger)

type LoggerFormatType

type LoggerFormatType uint8
const (
	LOGGER_FORMAT_TYPE_UNKNOWN LoggerFormatType = iota
	LOGGER_FORMAT_TYPE__JSON
	LOGGER_FORMAT_TYPE__TEXT
)

func ParseLoggerFormatTypeFromLabel

func ParseLoggerFormatTypeFromLabel(s string) (LoggerFormatType, error)

func ParseLoggerFormatTypeFromString

func ParseLoggerFormatTypeFromString(s string) (LoggerFormatType, error)

func (LoggerFormatType) ConstValues

func (v LoggerFormatType) ConstValues() []enum.IntStringerEnum

func (LoggerFormatType) Int

func (v LoggerFormatType) Int() int

func (LoggerFormatType) Label

func (v LoggerFormatType) Label() string

func (LoggerFormatType) MarshalText

func (v LoggerFormatType) MarshalText() ([]byte, error)

func (*LoggerFormatType) Scan

func (v *LoggerFormatType) Scan(src interface{}) error

func (LoggerFormatType) String

func (v LoggerFormatType) String() string

func (LoggerFormatType) TypeName

func (v LoggerFormatType) TypeName() string

func (*LoggerFormatType) UnmarshalText

func (v *LoggerFormatType) UnmarshalText(data []byte) error

func (LoggerFormatType) Value

func (v LoggerFormatType) Value() (driver.Value, error)

type LoggerOutputType

type LoggerOutputType uint8
const (
	LOGGER_OUTPUT_TYPE_UNKNOWN LoggerOutputType = iota
	LOGGER_OUTPUT_TYPE__ALWAYS
	LOGGER_OUTPUT_TYPE__ON_FAILURE
	LOGGER_OUTPUT_TYPE__NEVER
)

func ParseLoggerOutputTypeFromLabel

func ParseLoggerOutputTypeFromLabel(s string) (LoggerOutputType, error)

func ParseLoggerOutputTypeFromString

func ParseLoggerOutputTypeFromString(s string) (LoggerOutputType, error)

func (LoggerOutputType) ConstValues

func (v LoggerOutputType) ConstValues() []enum.IntStringerEnum

func (LoggerOutputType) Int

func (v LoggerOutputType) Int() int

func (LoggerOutputType) Label

func (v LoggerOutputType) Label() string

func (LoggerOutputType) MarshalText

func (v LoggerOutputType) MarshalText() ([]byte, error)

func (*LoggerOutputType) Scan

func (v *LoggerOutputType) Scan(src interface{}) error

func (LoggerOutputType) String

func (v LoggerOutputType) String() string

func (LoggerOutputType) TypeName

func (v LoggerOutputType) TypeName() string

func (*LoggerOutputType) UnmarshalText

func (v *LoggerOutputType) UnmarshalText(data []byte) error

func (LoggerOutputType) Value

func (v LoggerOutputType) Value() (driver.Value, error)

type ProjectAndMetaHook

type ProjectAndMetaHook struct {
	Name string
}

func (*ProjectAndMetaHook) Fire

func (h *ProjectAndMetaHook) Fire(entry *logrus.Entry) error

func (*ProjectAndMetaHook) Levels

func (h *ProjectAndMetaHook) Levels() []logrus.Level

type SpanMapExporter

type SpanMapExporter struct {
	trace.SpanExporter
	// contains filtered or unexported fields
}

func (*SpanMapExporter) ExportSpans

func (e *SpanMapExporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan) error

type SpanMapper

type SpanMapper func(trace.ReadOnlySpan) trace.ReadOnlySpan

func OutputFilter

func OutputFilter(output LoggerOutputType) SpanMapper

func SpanOnlyFilter

func SpanOnlyFilter() SpanMapper

type StdExporter

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

func (*StdExporter) ExportSpans

func (e *StdExporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan) error

func (*StdExporter) Shutdown

func (e *StdExporter) Shutdown(ctx context.Context) error

type WithExporter

type WithExporter func(trace.SpanExporter) trace.SpanExporter

func WithErrIgnoreExporter

func WithErrIgnoreExporter() WithExporter

func WithSpanMapExporter

func WithSpanMapExporter(mappers ...SpanMapper) WithExporter

Jump to

Keyboard shortcuts

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