Printf
-like function without f
suffix GO-W6006348}
349
350// PanicCtx print the panic message with ctx.
351func PanicCtx(ctx *context.Context, format string, args ...interface{}) {352 logCtx(ctx, logger.logger.Panic, format, args...)
353}
354
329}
330
331// FatalCtx print the fatal message with ctx.
332func FatalCtx(ctx *context.Context, format string, args ...interface{}) {333 if !logger.errorLogOff && logger.Level <= zapcore.FatalLevel {
334 logCtx(ctx, logger.logger.Fatal, format, args...)
335 }
308}
309
310// ErrorCtx print the error message with ctx.
311func ErrorCtx(ctx *context.Context, format string, args ...interface{}) {312 if !logger.errorLogOff && logger.Level <= zapcore.ErrorLevel {
313 logCtx(ctx, logger.logger.Error, format, args...)
314 }
287}
288
289// WarnCtx print the warning message with ctx.
290func WarnCtx(ctx *context.Context, format string, args ...interface{}) {291 if !logger.infoLogOff && logger.Level <= zapcore.WarnLevel {
292 logCtx(ctx, logger.logger.Warn, format, args...)
293 }
268
269type logFunc func(msg string, fields ...zapcore.Field)
270
271func logCtx(ctx *context.Context, logFunc logFunc, format string, args ...interface{}) {272 logFunc(fmt.Sprintf(format, args...), zap.String("traceID", trace.GetTraceID(ctx)))
273}
274
For Printf
-like functions they should be named correctly so that consumers of the function
use it correctly. It is recommended to use f
as suffix for such functions to make it clear
that arguments are preceded with format specifier.
func glog(format string, args ...any) {
log.Printf("glog " + format, args...)
}
func dump(w io.Writer, prefix, format string, args ...any) {
fmt.Fprintf(w, "dump " + format, args...)
}
func glogf(format string, args ...any) {
log.Printf("glog " + format, args...)
}
func dumpf(w io.Writer, prefix, format string, args ...any) {
fmt.Fprintf(w, "dump " + format, args...)
}