Documentation ¶
Index ¶
- Variables
- func InstallPipeline(output LoggerOutputType, format LoggerFormatType, exporter trace.SpanExporter) error
- func KeyValues(kvs ...interface{}) logrus.Fields
- func WithLogger(ctx context.Context, l Logger) context.Context
- func WithLoggerContext(l Logger) contextx.WithContext
- type ErrIgnoreExporter
- type Level
- type LevelSetter
- type Log
- type Logger
- func Discard() Logger
- func FromContext(ctx context.Context) Logger
- func Span(tracer string, s trace.Span) Logger
- func SpanContext(ctx context.Context, tracer string) (context.Context, Logger)
- func Start(ctx context.Context, name string, kvs ...interface{}) (context.Context, Logger)
- func Std() Logger
- func StdContext(ctx context.Context) (context.Context, Logger)
- type LoggerFormatType
- func (v LoggerFormatType) ConstValues() []enum.IntStringerEnum
- func (v LoggerFormatType) Int() int
- func (v LoggerFormatType) Label() string
- func (v LoggerFormatType) MarshalText() ([]byte, error)
- func (v *LoggerFormatType) Scan(src interface{}) error
- func (v LoggerFormatType) String() string
- func (v LoggerFormatType) TypeName() string
- func (v *LoggerFormatType) UnmarshalText(data []byte) error
- func (v LoggerFormatType) Value() (driver.Value, error)
- type LoggerOutputType
- func (v LoggerOutputType) ConstValues() []enum.IntStringerEnum
- func (v LoggerOutputType) Int() int
- func (v LoggerOutputType) Label() string
- func (v LoggerOutputType) MarshalText() ([]byte, error)
- func (v *LoggerOutputType) Scan(src interface{}) error
- func (v LoggerOutputType) String() string
- func (v LoggerOutputType) TypeName() string
- func (v *LoggerOutputType) UnmarshalText(data []byte) error
- func (v LoggerOutputType) Value() (driver.Value, error)
- type ProjectAndMetaHook
- type SpanMapExporter
- type SpanMapper
- type StdExporter
- type WithExporter
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 WithLoggerContext ¶ added in v1.1.0
func WithLoggerContext(l Logger) contextx.WithContext
Types ¶
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 ¶
ParseLevel takes a string level and returns the Logrus log level constant.
func (Level) LogrusLogLevel ¶
func (Level) MarshalText ¶
func (*Level) UnmarshalText ¶
type LevelSetter ¶
type Log ¶
type Log struct { Name string Level Level `env:""` Output LoggerOutputType `env:""` Format LoggerFormatType Exporter trace.SpanExporter `env:"-"` ReportCaller bool }
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 FromContext ¶
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
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
type ProjectAndMetaHook ¶
type ProjectAndMetaHook struct {
Name string
}
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
type WithExporter ¶
type WithExporter func(trace.SpanExporter) trace.SpanExporter
func WithErrIgnoreExporter ¶
func WithErrIgnoreExporter() WithExporter
func WithSpanMapExporter ¶
func WithSpanMapExporter(mappers ...SpanMapper) WithExporter
Click to show internal directories.
Click to hide internal directories.