flow

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Logging and Tracing

Index

Constants

View Source
const (
	XTraceId  = "X-B3-TraceId"
	XSpanId   = "X-B3-SpanId"
	XUsername = "x-username"
	XUserNo   = "x-userno"
	XRoleNo   = "x-roleno"
)

Variables

View Source
var (
	GetCallerFn    = src.GetCallerFn
	GetCallerFnUpN = src.GetCallerFnUpN
)
View Source
var (
	Infof  = zRail.Infof
	Tracef = zRail.Tracef
	Debugf = zRail.Debugf
	Warnf  = zRail.Warnf
	Errorf = zRail.Errorf
	Fatalf = zRail.Fatalf
	Debug  = zRail.Debug
	Info   = zRail.Info
	Warn   = zRail.Warn
	Error  = zRail.Error
	Fatal  = zRail.Fatal
)

Functions

func AddPropagationKey

func AddPropagationKey(key string)

Add propagation key for tracing

func AddPropagationKeys

func AddPropagationKeys(keys ...string)

Add propagation key for tracing

func BuildRollingLogFileWriter

func BuildRollingLogFileWriter(p NewRollingLogFileParam) *lumberjack.Logger

Create rolling file based logger

func BuildTraceHeadersAny

func BuildTraceHeadersAny(rail Rail) map[string]any

func BuildTraceHeadersStr

func BuildTraceHeadersStr(rail Rail) map[string]string

func ConfigDebugLogToInfo

func ConfigDebugLogToInfo(loggerName string, doRewrite bool)

func CustomFormatter

func CustomFormatter() logrus.Formatter

Get custom formatter logrus

func GetCtxInt

func GetCtxInt(ctx context.Context, key string) (int, bool)

Get value from context as an int.

string is also formatted as int if possible.

func GetCtxStr

func GetCtxStr(ctx context.Context, key string) (string, bool)

Get value from context as a string

int*, unit*, float* types are formatted as string, other types are returned as empty string

func GetLogrusLogger

func GetLogrusLogger() *logrus.Logger

func GetPropagationKeys

func GetPropagationKeys() []string

Get all existing propagation key

func IsDebugLevel

func IsDebugLevel() bool

Check whether current log level is DEBUG

func IsLogLevel

func IsLogLevel(logLevel string) bool

func IsTraceLevel

func IsTraceLevel() bool

func NewSpanId

func NewSpanId() string

Create new SpanId.

func NewTraceId

func NewTraceId() string

Create new TraceId.

func ParseLogLevel

func ParseLogLevel(logLevel string) (logrus.Level, bool)

Parse log level

func PreConfiguredFormatter

func PreConfiguredFormatter() logrus.Formatter

Get pre-configured TextFormatter for logrus

func SetLogLevel

func SetLogLevel(level string)

func SetLogOutput

func SetLogOutput(out io.Writer)

func TraceLogger

func TraceLogger(ctx context.Context) *logrus.Entry

Return logger with tracing infomation

func UsePropagationKeys

func UsePropagationKeys(forEach func(key string))

Types

type CTFormatter

type CTFormatter struct {
}

func (*CTFormatter) Format

func (c *CTFormatter) Format(entry *logrus.Entry) ([]byte, error)

type NewRollingLogFileParam

type NewRollingLogFileParam struct {
	Filename   string // filename
	MaxSize    int    // max file size in mb
	MaxAge     int    // max age in day
	MaxBackups int    // max number of files
}

type PlainStrFormatter

type PlainStrFormatter struct {
}

func (PlainStrFormatter) Format

func (p PlainStrFormatter) Format(e *logrus.Entry) ([]byte, error)

type PropagationKeys

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

type Rail

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

Rail, an object that carries trace infromation along with the execution.

It's essentially a thin wrapper of context.Context.

func EmptyRail

func EmptyRail() Rail

Create empty Rail.

func LoadPropagationKeysFromHeaders

func LoadPropagationKeysFromHeaders[T any](rail Rail, headers map[string]T) Rail

func NewRail

func NewRail(ctx context.Context) Rail

Create new Rail from context.

func StoreUser added in v0.4.11

func StoreUser(rail Rail, u User) Rail

Store User in Rail (trace).

func (Rail) Context

func (r Rail) Context() context.Context

func (Rail) CtxValInt

func (r Rail) CtxValInt(key string) int

func (Rail) CtxValStr

func (r Rail) CtxValStr(key string) string

func (Rail) CtxValue

func (r Rail) CtxValue(key string) any

func (Rail) Deadline

func (r Rail) Deadline() (deadline time.Time, ok bool)

func (Rail) Debug

func (r Rail) Debug(args ...interface{})

func (Rail) DebugTimeOp added in v0.4.8

func (r Rail) DebugTimeOp(start time.Time, pat string, args ...any)

func (Rail) Debugf

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

func (Rail) Debugln

func (r Rail) Debugln(args ...interface{})

func (Rail) Done

func (r Rail) Done() <-chan struct{}

func (Rail) Err

func (r Rail) Err() error

func (Rail) Error

func (r Rail) Error(args ...interface{})

func (Rail) ErrorIf

func (r Rail) ErrorIf(err error, op string, args ...any)

func (Rail) Errorf

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

func (Rail) Errorln

func (r Rail) Errorln(args ...interface{})

func (Rail) Fatal

func (r Rail) Fatal(args ...interface{})

func (Rail) Fatalf

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

func (Rail) Fatalln

func (r Rail) Fatalln(args ...interface{})

func (Rail) Info

func (r Rail) Info(args ...interface{})

func (Rail) Infof

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

func (Rail) Infoln

func (r Rail) Infoln(args ...interface{})

func (Rail) IsDone

func (r Rail) IsDone() bool

func (Rail) NewCtx

func (r Rail) NewCtx() Rail

Create a new Rail with a new Context

func (Rail) NewTrace

func (r Rail) NewTrace() Rail

func (Rail) NextSpan

func (r Rail) NextSpan() Rail

Create a new Rail with a new SpanId and a new Context

func (Rail) Panic

func (r Rail) Panic(args ...interface{})

func (Rail) Panicf

func (r Rail) Panicf(format string, args ...interface{})

func (Rail) Panicln

func (r Rail) Panicln(args ...interface{})

func (Rail) Print

func (r Rail) Print(args ...interface{})

func (Rail) Printf

func (r Rail) Printf(format string, args ...interface{})

func (Rail) Println

func (r Rail) Println(args ...interface{})

func (Rail) RoleNo added in v0.4.11

func (r Rail) RoleNo() string

func (Rail) SetGetCallFnUpN

func (r Rail) SetGetCallFnUpN(upN int) Rail

func (Rail) SpanId

func (r Rail) SpanId() string

func (Rail) TimeOp added in v0.4.8

func (r Rail) TimeOp(start time.Time, pat string, args ...any)

func (Rail) TraceId

func (r Rail) TraceId() string

func (Rail) Tracef

func (r Rail) Tracef(format string, args ...interface{})

func (Rail) User added in v0.4.11

func (r Rail) User() User

func (Rail) Username

func (r Rail) Username() string

func (Rail) Value

func (r Rail) Value(key any) any

func (Rail) Warn

func (r Rail) Warn(args ...interface{})

func (Rail) WarnIf

func (r Rail) WarnIf(err error, op string, args ...any)

func (Rail) Warnf

func (r Rail) Warnf(format string, args ...interface{})

func (Rail) Warnln

func (r Rail) Warnln(args ...interface{})

func (Rail) WithCancel

func (r Rail) WithCancel() (Rail, context.CancelFunc)

Create new Rail with context's CancelFunc

func (Rail) WithCtxVal

func (r Rail) WithCtxVal(key any, val any) Rail

func (Rail) WithGetCallFnUpN

func (r Rail) WithGetCallFnUpN(upN int) Rail

func (Rail) WithName

func (r Rail) WithName(name string) Rail

func (Rail) WithRoleNo added in v0.4.11

func (r Rail) WithRoleNo(v string) Rail

func (Rail) WithSpanId

func (r Rail) WithSpanId(id string) Rail

func (Rail) WithTimeout

func (r Rail) WithTimeout(timeout time.Duration) (Rail, context.CancelFunc)

Create new Rail with timeout and context's CancelFunc

func (Rail) WithTraceId

func (r Rail) WithTraceId(id string) Rail

func (Rail) WithUsername

func (r Rail) WithUsername(v string) Rail

func (Rail) ZeroTrace

func (r Rail) ZeroTrace() Rail

type User added in v0.4.11

type User struct {
	UserNo   string `json:"userNo"`
	Username string `json:"username"`
	RoleNo   string `json:"roleNo"`
	IsNil    bool   `json:"-"`
}

func GetUser added in v0.4.11

func GetUser(rail Rail) User

Get User from Rail (trace).

func NilUser added in v0.4.11

func NilUser() User

Get a 'nil' User.

func (User) IsZero added in v0.4.11

func (u User) IsZero() bool

Jump to

Keyboard shortcuts

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