Skip to content

Logging for better analysis

Patcherly analyzes the error text your connector sends from monitored log files. Message-only lines (no stack frames) often leave the AI without enough call-site context to propose a reliable patch. Thin file or site environment context can also reduce accuracy — see Context collection.

Patcherly does not inject tracing into your app (unlike APM SDKs). Standalone PHP, Python, and Node connectors run outside your process and only see what lands in watched logs.

Enable full exception stacks in your logger so the connector can forward them.

What a good log event looks like

Prefer one multi-line event that includes:

  1. The error message / exception type
  2. Stack frames with file paths and line numbers
  3. (Optional) a clear “thrown in” / closing locus for PHP

Path-only fatals (a path on the message line but no frames) are still ingestible when a path can be extracted, but analysis quality is usually weaker. Prefer a full stack when your framework can emit one.

PHP / WordPress

Bad (message only, or path on the fatal line with no frames):

ERROR Contesto tenant missing
[23-Oct-2026 14:02:11 UTC] PHP Fatal error:  Uncaught Error: Tenant Context in /var/www/html/wp-content/themes/my-theme/inc/cart.php:142

Good (message + Stack trace: / #N frames and/or thrown in … on line N):

[23-Oct-2026 14:02:11 UTC] PHP Fatal error:  Uncaught Error: Tenant Context in /var/www/html/wp-content/themes/my-theme/inc/cart.php:142
Stack trace:
#0 /var/www/html/wp-includes/template-loader.php(132): include()
#1 /var/www/html/wp-blog-header.php(19): require_once()
#2 /var/www/html/index.php(17): require()
  thrown in /var/www/html/wp-content/themes/my-theme/inc/cart.php on line 142

Python

Bad (exception string only, no Traceback / File frames):

ERROR app: Tenant Context
ValueError: Tenant Context

Good (Traceback header or orphan File "…", line N frames with paths):

ERROR app: Tenant Context
Traceback (most recent call last):
  File "/app/views/checkout.py", line 88, in create_order
    ctx = require_tenant(request)
  File "/app/services/tenant.py", line 14, in require_tenant
    raise ValueError("Tenant Context")
ValueError: Tenant Context

Node.js

Bad (message only, no at …(file:line:col) frames):

TypeError: Tenant Context
{"level":50,"msg":"Tenant Context"}

Good (error type/message plus stack frames with file paths and line:column):

TypeError: Tenant Context
    at requireTenant (/app/services/tenant.js:14:11)
    at createOrder (/app/routes/checkout.js:88:17)
    at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)

Bare frames such as at /app/routes/checkout.js:88:17 are also useful when present.

WordPress

  1. In wp-config.php, enable logging with display off in production:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );
  1. Confirm wp-content/debug.log (or your custom log path) is on the site’s Monitored Logs list.
  2. Emergency Rescue can record a single-line fatal when PHP shuts down. That line often has a path but no stack frames. For better analysis, keep debug.log monitoring enabled so the fuller Stack trace: block is ingested when WordPress writes it.

See also WordPress connector and Custom log paths.

PHP (including Laravel)

  • Ensure log_errors is on and fatals reach the file Patcherly watches.
  • Laravel: prefer report($e) / Log::error(..., ['exception' => $e]) so Monolog includes the stack. Confirm storage/logs/laravel.log (or your channel path) is monitored.
  • Avoid logging only $e->getMessage() without the exception object.

Python

  • Use logger.exception("…") or logger.error("…", exc_info=True) inside except blocks so the Traceback is written.
  • Framework defaults (Django / Flask / FastAPI) usually log stacks to stderr or a configured file — point Patcherly at that file under Monitored Logs.
  • Avoid logger.error(str(e)) alone when you need a patchable analysis.

Node.js

  • Log err.stack (or a serializer that includes stack) to the watched file.
  • For Express-style handlers, log the full Error object, not only err.message.
  • Structured loggers (pino / winston): enable stack serializers for error objects.

Missing path vs missing stack

  • Ignored — no source file path: the log had no extractable path, so Patcherly cannot back up or patch. Fix logging so paths appear (often by enabling stacks). See the tip on ignored errors in the dashboard.
  • Not patchable after analysis: analysis finished without a draft patch. A missing stack is a common cause; thin FILE CONTEXT can also contribute (Context collection, Auto-analysis).