// Package logger define log struct of modelRT project package logger import ( "context" "sync" "go.uber.org/zap" "go.uber.org/zap/zapcore" ) var ( f *facade fOnce sync.Once ) type facade struct { _logger *zap.Logger } // Debug define facade func of debug level log func Debug(ctx context.Context, msg string, kv ...any) { logFacade().log(ctx, zapcore.DebugLevel, msg, kv...) } // Info define facade func of info level log func Info(ctx context.Context, msg string, kv ...any) { logFacade().log(ctx, zapcore.InfoLevel, msg, kv...) } // Warn define facade func of warn level log func Warn(ctx context.Context, msg string, kv ...any) { logFacade().log(ctx, zapcore.WarnLevel, msg, kv...) } // Error define facade func of error level log func Error(ctx context.Context, msg string, kv ...any) { logFacade().log(ctx, zapcore.ErrorLevel, msg, kv...) } func (f *facade) log(ctx context.Context, lvl zapcore.Level, msg string, kv ...any) { f.logSkip(ctx, lvl, 0, msg, kv...) } func (f *facade) logSkip(ctx context.Context, lvl zapcore.Level, extraSkip int, msg string, kv ...any) { fields := makeLogFieldsSkip(ctx, extraSkip, kv...) ce := f._logger.Check(lvl, msg) ce.Write(fields...) } // ErrorSkip logs at error level with extra caller skip frames for wrapper functions. func ErrorSkip(ctx context.Context, extraSkip int, msg string, kv ...any) { logFacade().logSkip(ctx, zapcore.ErrorLevel, extraSkip, msg, kv...) } // WarnSkip logs at warn level with extra caller skip frames for wrapper functions. func WarnSkip(ctx context.Context, extraSkip int, msg string, kv ...any) { logFacade().logSkip(ctx, zapcore.WarnLevel, extraSkip, msg, kv...) } // InfoSkip logs at info level with extra caller skip frames for wrapper functions. func InfoSkip(ctx context.Context, extraSkip int, msg string, kv ...any) { logFacade().logSkip(ctx, zapcore.InfoLevel, extraSkip, msg, kv...) } func logFacade() *facade { fOnce.Do(func() { f = &facade{ _logger: GetLoggerInstance(), } }) return f }