mirror of
https://gitee.com/johng/gf
synced 2026-07-08 22:40:30 +08:00
upgrade otel to v1.0.0 for compatibility
This commit is contained in:
@ -11,11 +11,13 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"github.com/gogf/gf/debug/gdebug"
|
||||
"github.com/gogf/gf/internal/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -43,23 +45,35 @@ func SetEnabled(enabled bool) {
|
||||
// Print prints `v` with newline using fmt.Println.
|
||||
// The parameter `v` can be multiple variables.
|
||||
func Print(ctx context.Context, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprint(v...), false)
|
||||
}
|
||||
|
||||
// Printf prints `v` with format `format` using fmt.Printf.
|
||||
// The parameter `v` can be multiple variables.
|
||||
func Printf(ctx context.Context, format string, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprintf(format, v...), false)
|
||||
}
|
||||
|
||||
// Error prints `v` with newline using fmt.Println.
|
||||
// The parameter `v` can be multiple variables.
|
||||
func Error(ctx context.Context, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprint(v...), true)
|
||||
}
|
||||
|
||||
// Errorf prints `v` with format `format` using fmt.Printf.
|
||||
func Errorf(ctx context.Context, format string, v ...interface{}) {
|
||||
if !isGFDebug {
|
||||
return
|
||||
}
|
||||
doPrint(ctx, fmt.Sprintf(format, v...), true)
|
||||
}
|
||||
|
||||
@ -94,7 +108,7 @@ func doPrint(ctx context.Context, content string, stack bool) {
|
||||
return
|
||||
}
|
||||
buffer := bytes.NewBuffer(nil)
|
||||
buffer.WriteString(now())
|
||||
buffer.WriteString(time.Now().Format("2006-01-02 15:04:05.000"))
|
||||
buffer.WriteString(" [INTE] ")
|
||||
buffer.WriteString(file())
|
||||
buffer.WriteString(" ")
|
||||
@ -104,7 +118,7 @@ func doPrint(ctx context.Context, content string, stack bool) {
|
||||
buffer.WriteString(content)
|
||||
buffer.WriteString("\n")
|
||||
if stack {
|
||||
buffer.WriteString(gdebug.StackWithFilter(stackFilterKey))
|
||||
buffer.WriteString(gdebug.StackWithFilter([]string{stackFilterKey}))
|
||||
}
|
||||
fmt.Print(buffer.String())
|
||||
}
|
||||
@ -121,13 +135,8 @@ func traceIdStr(ctx context.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// now returns current time string.
|
||||
func now() string {
|
||||
return time.Now().Format("2006-01-02 15:04:05.000")
|
||||
}
|
||||
|
||||
// file returns caller file name along with its line number.
|
||||
func file() string {
|
||||
_, p, l := gdebug.CallerWithFilter(stackFilterKey)
|
||||
_, p, l := gdebug.CallerWithFilter([]string{stackFilterKey})
|
||||
return fmt.Sprintf(`%s:%d`, filepath.Base(p), l)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user