MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / callHostLog

Method callHostLog

internal/pluginhost/host_callbacks.go:322–356  ·  view source on GitHub ↗
(ctx context.Context, request []byte)

Source from the content-addressed store, hash-verified

320}
321
322func (h *Host) callHostLog(ctx context.Context, request []byte) ([]byte, error) {
323 var req rpcHostLogRequest
324 if errUnmarshal := json.Unmarshal(request, &req); errUnmarshal != nil {
325 return nil, fmt.Errorf("decode host log request: %w", errUnmarshal)
326 }
327 ctx = h.resolveCallbackContext(req.HostCallbackID, ctx)
328 message := strings.TrimSpace(req.Message)
329 if message == "" {
330 message = "plugin log"
331 }
332 fields := log.Fields{}
333 for key, value := range req.Fields {
334 key = strings.TrimSpace(key)
335 if key != "" {
336 fields[key] = value
337 }
338 }
339 if requestID := logging.GetRequestID(ctx); requestID != "" {
340 fields["request_id"] = requestID
341 }
342 entry := log.WithFields(fields)
343 switch strings.ToLower(strings.TrimSpace(req.Level)) {
344 case "trace":
345 entry.Trace(message)
346 case "info":
347 entry.Info(message)
348 case "warn", "warning":
349 entry.Warn(message)
350 case "error":
351 entry.Error(message)
352 default:
353 entry.Debug(message)
354 }
355 return marshalRPCResult(rpcEmptyResponse{})
356}

Callers 1

callFromPluginMethod · 0.95

Calls 4

GetRequestIDFunction · 0.92
marshalRPCResultFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected