Documentation
¶
Overview ¶
Package log 提供统一的日志包装和上下文管理
核心功能: 1. CubeWrapperLogEntry - 对 CubeLog.Entry 的包装,提供便利的日志方法 2. Context 集成 - 支持通过 context 传递和获取 logger 实例 3. 日志桥接 - 将 klog、logrus、containerd log 统一到 CubeLog
使用示例:
// 获取当前上下文的 logger
logger := log.GetLogger(ctx)
logger.WithField("request_id", "123").Info("message")
// 创建新的上下文并关联 logger
newCtx := log.WithLogger(ctx, logger)
// 新上下文中的日志都会使用这个 logger
日志链路:
业务代码 (CubeLog.Entry)
↓
CubeWrapperLogEntry (本包)
↓
context 传递与关联
↓
klog/logrus/containerd log 桥接
↓
日志文件输出
Index ¶
- Constants
- Variables
- func IsDebug() bool
- func ReNewLogger(ctx context.Context) context.Context
- func SetContainerdLog()
- func SetKlog()
- func WithDebugStack() string
- func WithJsonValue(obj any) string
- func WithLogger(ctx context.Context, e *CubeWrapperLogEntry) context.Context
- type CubeWrapperLogEntry
- func (w *CubeWrapperLogEntry) Debug(args ...interface{})
- func (w *CubeWrapperLogEntry) Debugf(format string, args ...interface{})
- func (w *CubeWrapperLogEntry) Error(args ...interface{})
- func (w *CubeWrapperLogEntry) Errorf(format string, args ...interface{})
- func (w *CubeWrapperLogEntry) Fatal(args ...interface{})
- func (w *CubeWrapperLogEntry) Fatalf(format string, args ...interface{})
- func (w *CubeWrapperLogEntry) Info(args ...interface{})
- func (w *CubeWrapperLogEntry) Infof(format string, args ...interface{})
- func (w *CubeWrapperLogEntry) Tracef(format string, v ...interface{})
- func (w *CubeWrapperLogEntry) Warn(args ...interface{})
- func (w *CubeWrapperLogEntry) Warnf(format string, args ...interface{})
- func (w *CubeWrapperLogEntry) WithError(err error) *CubeWrapperLogEntry
- func (w *CubeWrapperLogEntry) WithField(key string, value any) *CubeWrapperLogEntry
- func (w *CubeWrapperLogEntry) WithFields(fields CubeLog.Fields) *CubeWrapperLogEntry
Constants ¶
View Source
const ( LogFiledPrefix = "LogIndex" MaxFieldValueLength = 100 )
Variables ¶
View Source
var ( G = GetLogger L = GetLogger(context.Background()) )
View Source
var AuditLogger *CubeLog.Logger = CubeLog.GetDefaultLogger()
Functions ¶
func SetContainerdLog ¶
func SetContainerdLog()
func WithDebugStack ¶
func WithDebugStack() string
func WithJsonValue ¶
func WithLogger ¶
func WithLogger(ctx context.Context, e *CubeWrapperLogEntry) context.Context
Types ¶
type CubeWrapperLogEntry ¶
type CubeWrapperLogEntry struct {
*CubeLog.Entry
}
func GetLogger ¶
func GetLogger(ctx context.Context) *CubeWrapperLogEntry
func NewWrapperLogEntry ¶
func NewWrapperLogEntry(entry *CubeLog.Entry) *CubeWrapperLogEntry
func (*CubeWrapperLogEntry) Debug ¶
func (w *CubeWrapperLogEntry) Debug(args ...interface{})
func (*CubeWrapperLogEntry) Debugf ¶
func (w *CubeWrapperLogEntry) Debugf(format string, args ...interface{})
func (*CubeWrapperLogEntry) Error ¶
func (w *CubeWrapperLogEntry) Error(args ...interface{})
func (*CubeWrapperLogEntry) Errorf ¶
func (w *CubeWrapperLogEntry) Errorf(format string, args ...interface{})
func (*CubeWrapperLogEntry) Fatal ¶
func (w *CubeWrapperLogEntry) Fatal(args ...interface{})
func (*CubeWrapperLogEntry) Fatalf ¶
func (w *CubeWrapperLogEntry) Fatalf(format string, args ...interface{})
func (*CubeWrapperLogEntry) Info ¶
func (w *CubeWrapperLogEntry) Info(args ...interface{})
func (*CubeWrapperLogEntry) Infof ¶
func (w *CubeWrapperLogEntry) Infof(format string, args ...interface{})
func (*CubeWrapperLogEntry) Tracef ¶
func (w *CubeWrapperLogEntry) Tracef(format string, v ...interface{})
func (*CubeWrapperLogEntry) Warn ¶
func (w *CubeWrapperLogEntry) Warn(args ...interface{})
func (*CubeWrapperLogEntry) Warnf ¶
func (w *CubeWrapperLogEntry) Warnf(format string, args ...interface{})
func (*CubeWrapperLogEntry) WithError ¶
func (w *CubeWrapperLogEntry) WithError(err error) *CubeWrapperLogEntry
func (*CubeWrapperLogEntry) WithField ¶
func (w *CubeWrapperLogEntry) WithField(key string, value any) *CubeWrapperLogEntry
func (*CubeWrapperLogEntry) WithFields ¶
func (w *CubeWrapperLogEntry) WithFields(fields CubeLog.Fields) *CubeWrapperLogEntry
Click to show internal directories.
Click to hide internal directories.