Skip to content

Logging

Enable API request/response logging to monitor HubSpot API activity. Disabled by default.

Configuration

ini
# Enable logging
HUBSPOT_LOGGING_ENABLED=true

# Optional: send logs to a specific channel (defaults to your app's default channel)
HUBSPOT_LOGGING_CHANNEL=hubspot

# Optional: include request/response bodies (off by default — may contain PII)
HUBSPOT_LOGGING_BODIES=false

When enabled, every API response is logged at debug level with the HTTP method, URL, status code, and duration in milliseconds. When body logging is enabled, request and response payloads are included as well.

Body Sanitization

When body logging is enabled, you can provide a body_sanitizer closure to redact sensitive data before it is written to logs. The closure receives the body array and must return a sanitized array.

RedactKeys Helper

Use the built-in RedactKeys helper to redact specific property keys:

php
use Rollogi\LaravelHubspot\Middleware\RedactKeys;

'logging' => [
    'enabled' => true,
    'log_bodies' => true,
    'body_sanitizer' => new RedactKeys([
        'email', 'firstname', 'lastname', 'phone', 'mobilephone',
    ]),
],

Custom Closure

Or provide a custom closure for full control:

php
'logging' => [
    'enabled' => true,
    'log_bodies' => true,
    'body_sanitizer' => function (array $data): array {
        // Your custom sanitization logic
        unset($data['properties']['email']);
        return $data;
    },
],

When body_sanitizer is null (default), bodies are logged as-is.