xlog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: MulanPSL-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldKeyMsg         = "msg"
	FieldKeyLevel       = "level"
	FieldKeyTime        = "time"
	FieldKeyLogrusError = "logrus_error"
	FieldKeyFunc        = "func"
	FieldKeyFile        = "file"
)

Default key names for the default fields

View Source
const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel logrus.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
)

Variables

View Source
var File_logproto_proto protoreflect.FileDescriptor

Functions

func Debug

func Debug(v ...interface{})

Debug provides debug level logging

func Debugf

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

Debugf provides debug level logging

func Error

func Error(v ...interface{})

Error provides warn level logging

func Errorf

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

Errorf provides warn level logging

func Fatal

func Fatal(v ...interface{})

Fatal logs with Log and then exits with os.Exit(1)

func Fatalf

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

Fatalf logs with Logf and then exits with os.Exit(1)

func GetLevel

func GetLevel() logrus.Level

GetLevel returns the current level

func GetLogger

func GetLogger() *logrus.Logger

GetLogger returns the local logger

func Info

func Info(v ...interface{})

Info provides info level logging

func Infof

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

Infof provides info level logging

func Log

func Log(v ...interface{})

Log makes use of github.com/go-log/log.Log

func Logf

func Logf(format string, v ...interface{})

Logf makes use of github.com/go-log/log.Logf

func Name

func Name(name string)

Name Set service name

func Pretty

func Pretty(v ...interface{})

Pretty provides pretty trace level logging

func PrettyLog

func PrettyLog(l logrus.Level, v ...interface{})

PrettyLog provides pretty logging with level specified

func PrettyLogf

func PrettyLogf(l logrus.Level, format string, v ...interface{})

PrettyLogf provides pretty logging with level specified

func Prettyf

func Prettyf(format string, v ...interface{})

Prettyf provides pretty trace level logging

func RpcTrace

func RpcTrace(method string, request interface{}, response interface{})

RpcTrace rpc logger

func SetCaller

func SetCaller(isReport bool)

SetCaller 是否显示调用位置

func SetLevel

func SetLevel(l string)

SetLevel sets the log level

func SetLoki

func SetLoki(uri string) error

SetLoki

func Trace

func Trace(v ...interface{})

Trace provides trace level logging

func Tracef

func Tracef(format string, v ...interface{})

Tracef provides trace level logging

func Warn

func Warn(v ...interface{})

Warn provides warn level logging

func Warnf

func Warnf(format string, v ...interface{})

Warnf provides warn level logging

func WithLevel

func WithLevel(l logrus.Level, v ...interface{})

WithLevel logs with the level specified

func WithLevelf

func WithLevelf(l logrus.Level, format string, v ...interface{})

WithLevelf logs with the level specified

Types

type CallerHook

type CallerHook struct{}

CallerHook is a hook designed for dealing with logs in test scenarios.

func NewCallerHook

func NewCallerHook(logger *logrus.Logger) *CallerHook

NewCallerHook installs a test hook for a given local logger.

func (*CallerHook) Fire

func (t *CallerHook) Fire(e *logrus.Entry) error

func (*CallerHook) Levels

func (t *CallerHook) Levels() []logrus.Level

type Entry

type Entry struct {
	Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	Line      string               `protobuf:"bytes,2,opt,name=line,proto3" json:"line,omitempty"`
	// contains filtered or unexported fields
}

func (*Entry) Descriptor deprecated

func (*Entry) Descriptor() ([]byte, []int)

Deprecated: Use Entry.ProtoReflect.Descriptor instead.

func (*Entry) GetLine

func (x *Entry) GetLine() string

func (*Entry) GetTimestamp

func (x *Entry) GetTimestamp() *timestamp.Timestamp

func (*Entry) ProtoMessage

func (*Entry) ProtoMessage()

func (*Entry) ProtoReflect

func (x *Entry) ProtoReflect() protoreflect.Message

func (*Entry) Reset

func (x *Entry) Reset()

func (*Entry) String

func (x *Entry) String() string

type FieldMap

type FieldMap map[fieldKey]string

FieldMap allows customization of the key names for default fields.

type Formatter

type Formatter interface {
	Format(*logrus.Entry) ([]byte, error)
}

The Formatter interface is used to implement a custom Formatter. It takes an `Entry`. It exposes all the fields, including the default ones:

* `entry.Data["msg"]`. The message passed from Info, Warn, Error .. * `entry.Data["time"]`. The timestamp. * `entry.Data["level"]. The level the entry was logged at.

Any additional fields added with `WithField` or `WithFields` are also in `entry.Data`. Format is expected to return an array of bytes which are then logged to `logger.Out`.

type JSONFormatter

type JSONFormatter struct {
	// TimestampFormat sets the format used for marshaling timestamps.
	TimestampFormat string

	// DisableTimestamp allows disabling automatic timestamps in output
	DisableTimestamp bool

	// DisableHTMLEscape allows disabling html escaping in output
	DisableHTMLEscape bool

	// DataKey allows users to put all the log entry parameters into a nested dictionary at a given key.
	DataKey string

	// FieldMap allows users to customize the names of keys for default fields.
	// As an example:
	// formatter := &JSONFormatter{
	//   	FieldMap: FieldMap{
	// 		 FieldKeyTime:  "@timestamp",
	// 		 FieldKeyLevel: "@level",
	// 		 FieldKeyMsg:   "@message",
	// 		 FieldKeyFunc:  "@caller",
	//    },
	// }
	FieldMap FieldMap

	// CallerPrettyfier can be set by the user to modify the content
	// of the function and file keys in the json data when ReportCaller is
	// activated. If any of the returned value is the empty string the
	// corresponding key will be removed from json fields.
	CallerPrettyfier func(*runtime.Frame) (function string, file string)

	// PrettyPrint will indent all json logs
	PrettyPrint bool
}

JSONFormatter formats logs into parsable json

func (*JSONFormatter) Format

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

Format renders a single log entry

type Loki

type Loki struct {
	LokiURL   string
	BatchWait time.Duration
	BatchSize int
	// contains filtered or unexported fields
}

func NewLoki

func NewLoki(URL string, service string, batchSize, batchWait int) (*Loki, error)

func (*Loki) AddData

func (l *Loki) AddData(key, value string)

func (*Loki) Close

func (l *Loki) Close()

func (*Loki) Fire

func (l *Loki) Fire(entry *logrus.Entry) error

func (*Loki) Levels

func (l *Loki) Levels() []logrus.Level

type LokiFormatter

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

	// Force disabling colors.
	DisableColors bool

	// Force quoting of all values
	ForceQuote bool

	// DisableQuote disables quoting for all values.
	// DisableQuote will have a lower priority than ForceQuote.
	// If both of them are set to true, quote will be forced on all values.
	DisableQuote bool

	// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
	EnvironmentOverrideColors 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

	// TimestampFormat 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

	// The keys sorting function, when uninitialized it uses sort.Strings.
	SortingFunc func([]string) []string

	// Disables the truncation of the level text to 4 characters.
	DisableLevelTruncation bool

	// PadLevelText Adds padding the level text so that all the levels output at the same length
	// PadLevelText is a superset of the DisableLevelTruncation option
	PadLevelText bool

	// QuoteEmptyFields will wrap empty fields in quotes if true
	QuoteEmptyFields bool

	// FieldMap allows users to customize the names of keys for default fields.
	// As an example:
	// formatter := &LokiFormatter{
	//     FieldMap: FieldMap{
	//         FieldKeyTime:  "@timestamp",
	//         FieldKeyLevel: "@level",
	//         FieldKeyMsg:   "@message"}}
	FieldMap FieldMap

	// CallerPrettyfier can be set by the user to modify the content
	// of the function and file keys in the data when ReportCaller is
	// activated. If any of the returned value is the empty string the
	// corresponding key will be removed from fields.
	CallerPrettyfier func(*runtime.Frame) (function string, file string)
	// contains filtered or unexported fields
}

LokiFormatter formats logs into text

func (*LokiFormatter) Format

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

Format renders a single log entry

type PushRequest

type PushRequest struct {
	Streams []*Stream `protobuf:"bytes,1,rep,name=streams,proto3" json:"streams,omitempty"`
	// contains filtered or unexported fields
}

func (*PushRequest) Descriptor deprecated

func (*PushRequest) Descriptor() ([]byte, []int)

Deprecated: Use PushRequest.ProtoReflect.Descriptor instead.

func (*PushRequest) GetStreams

func (x *PushRequest) GetStreams() []*Stream

func (*PushRequest) ProtoMessage

func (*PushRequest) ProtoMessage()

func (*PushRequest) ProtoReflect

func (x *PushRequest) ProtoReflect() protoreflect.Message

func (*PushRequest) Reset

func (x *PushRequest) Reset()

func (*PushRequest) String

func (x *PushRequest) String() string

type Stream

type Stream struct {
	Labels  string   `protobuf:"bytes,1,opt,name=labels,proto3" json:"labels,omitempty"`
	Entries []*Entry `protobuf:"bytes,2,rep,name=entries,proto3" json:"entries,omitempty"`
	// contains filtered or unexported fields
}

func (*Stream) Descriptor deprecated

func (*Stream) Descriptor() ([]byte, []int)

Deprecated: Use Stream.ProtoReflect.Descriptor instead.

func (*Stream) GetEntries

func (x *Stream) GetEntries() []*Entry

func (*Stream) GetLabels

func (x *Stream) GetLabels() string

func (*Stream) ProtoMessage

func (*Stream) ProtoMessage()

func (*Stream) ProtoReflect

func (x *Stream) ProtoReflect() protoreflect.Message

func (*Stream) Reset

func (x *Stream) Reset()

func (*Stream) String

func (x *Stream) String() string

type TextFormatter

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

	// Force disabling colors.
	DisableColors bool

	// Force quoting of all values
	ForceQuote bool

	// DisableQuote disables quoting for all values.
	// DisableQuote will have a lower priority than ForceQuote.
	// If both of them are set to true, quote will be forced on all values.
	DisableQuote bool

	// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
	EnvironmentOverrideColors 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

	// TimestampFormat 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

	// The keys sorting function, when uninitialized it uses sort.Strings.
	SortingFunc func([]string) []string

	// Disables the truncation of the level text to 4 characters.
	DisableLevelTruncation bool

	// PadLevelText Adds padding the level text so that all the levels output at the same length
	// PadLevelText is a superset of the DisableLevelTruncation option
	PadLevelText bool

	// QuoteEmptyFields will wrap empty fields in quotes if true
	QuoteEmptyFields bool

	// FieldMap allows users to customize the names of keys for default fields.
	// As an example:
	// formatter := &TextFormatter{
	//     FieldMap: FieldMap{
	//         FieldKeyTime:  "@timestamp",
	//         FieldKeyLevel: "@level",
	//         FieldKeyMsg:   "@message"}}
	FieldMap FieldMap

	// CallerPrettyfier can be set by the user to modify the content
	// of the function and file keys in the data when ReportCaller is
	// activated. If any of the returned value is the empty string the
	// corresponding key will be removed from fields.
	CallerPrettyfier func(*runtime.Frame) (function string, file string)
	// contains filtered or unexported fields
}

TextFormatter formats logs into text

func (*TextFormatter) Format

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

Format renders a single log entry

Jump to

Keyboard shortcuts

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