mirror of
https://github.com/alibaba/higress.git
synced 2026-06-03 01:27:27 +08:00
modify log-format, then every plugin log is associated with access log (#1454)
This commit is contained in:
@@ -36,7 +36,12 @@ type Log struct {
|
||||
}
|
||||
|
||||
func (l Log) log(level LogLevel, msg string) {
|
||||
msg = fmt.Sprintf("[%s] %s", l.pluginName, msg)
|
||||
requestIDRaw, _ := proxywasm.GetProperty([]string{"x_request_id"})
|
||||
requestID := string(requestIDRaw)
|
||||
if requestID == "" {
|
||||
requestID = "nil"
|
||||
}
|
||||
msg = fmt.Sprintf("[%s] [%s] %s", l.pluginName, requestID, msg)
|
||||
switch level {
|
||||
case LogLevelTrace:
|
||||
proxywasm.LogTrace(msg)
|
||||
@@ -54,7 +59,12 @@ func (l Log) log(level LogLevel, msg string) {
|
||||
}
|
||||
|
||||
func (l Log) logFormat(level LogLevel, format string, args ...interface{}) {
|
||||
format = fmt.Sprintf("[%s] %s", l.pluginName, format)
|
||||
requestIDRaw, _ := proxywasm.GetProperty([]string{"x_request_id"})
|
||||
requestID := string(requestIDRaw)
|
||||
if requestID == "" {
|
||||
requestID = "nil"
|
||||
}
|
||||
format = fmt.Sprintf("[%s] [%s] %s", l.pluginName, requestID, format)
|
||||
switch level {
|
||||
case LogLevelTrace:
|
||||
proxywasm.LogTracef(format, args...)
|
||||
|
||||
@@ -370,6 +370,8 @@ func (ctx *CommonHttpCtx[PluginConfig]) SetResponseBodyBufferLimit(size uint32)
|
||||
}
|
||||
|
||||
func (ctx *CommonHttpCtx[PluginConfig]) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
|
||||
requestID, _ := proxywasm.GetHttpRequestHeader("x-request-id")
|
||||
_ = proxywasm.SetProperty([]string{"x_request_id"}, []byte(requestID))
|
||||
config, err := ctx.plugin.GetMatchConfig()
|
||||
if err != nil {
|
||||
ctx.plugin.vm.log.Errorf("get match config failed, err:%v", err)
|
||||
|
||||
Reference in New Issue
Block a user