add plugin start log in sdk (#1831)

This commit is contained in:
rinfx
2025-03-03 15:37:23 +08:00
committed by GitHub
parent 4f1901586a
commit 988e2c1fa7
2 changed files with 17 additions and 4 deletions

View File

@@ -44,10 +44,12 @@ type Log interface {
Errorf(format string, args ...interface{})
Critical(msg string)
Criticalf(format string, args ...interface{})
resetID(pluginID string)
}
type DefaultLog struct {
pluginName string
pluginID string
}
func (l *DefaultLog) log(level LogLevel, msg string) {
@@ -56,7 +58,7 @@ func (l *DefaultLog) log(level LogLevel, msg string) {
if requestID == "" {
requestID = "nil"
}
msg = fmt.Sprintf("[%s] [%s] %s", l.pluginName, requestID, msg)
msg = fmt.Sprintf("[%s] [%s] [%s] %s", l.pluginName, l.pluginID, requestID, msg)
switch level {
case LogLevelTrace:
proxywasm.LogTrace(msg)
@@ -79,7 +81,7 @@ func (l *DefaultLog) logFormat(level LogLevel, format string, args ...interface{
if requestID == "" {
requestID = "nil"
}
format = fmt.Sprintf("[%s] [%s] %s", l.pluginName, requestID, format)
format = fmt.Sprintf("[%s] [%s] [%s] %s", l.pluginName, l.pluginID, requestID, format)
switch level {
case LogLevelTrace:
proxywasm.LogTracef(format, args...)
@@ -143,3 +145,7 @@ func (l *DefaultLog) Critical(msg string) {
func (l *DefaultLog) Criticalf(format string, args ...interface{}) {
l.logFormat(LogLevelCritical, format, args...)
}
func (l *DefaultLog) resetID(pluginID string) {
l.pluginID = pluginID
}