Skip to main content
This documentation outlines how to configure logging with the AppSignal for PHP package.

Configure logging

🔐 Do not send Personal Identifiable Information (PII) to AppSignal. Filter PII (e.g., names, emails) from logs and use an ID, hash, or pseudonymized identifier instead.

For HIPAA-covered entities, more information about signing a Business Associate Agreement (BAA) can be found in our Business Add-Ons documentation.
You do not need to create a log source to send logs from the AppSignal for PHP integration. An “application” log source will be created automatically. The AppSignal for PHP package uses OpenTelemetry’s logging capabilities to send logs to AppSignal.

Laravel

If you’re using the Laravel framework, the AppSignal for PHP package automatically sends your logs to AppSignal. You do not need to configure Monolog directly.

Symfony

If you’re using the Symfony framework, the easiest way to send logs to AppSignal is by using the MonologBundle. Install the Monolog auto-instrumentation package.
Shell
composer require open-telemetry/opentelemetry-logger-monolog
Add a service definition for 'appsignal.monolog.handler' that uses the Appsignal\Integrations\Monolog\Handler class.
config/services.yaml
services:
  # ... other services

  appsignal.monolog.handler:
    class: Appsignal\Integrations\Monolog\Handler
    factory: ['Appsignal\Integrations\Monolog\Handler', "withLevel"]
    arguments: ["info"] # configure log level that will reach AppSignal
Add appsignal.monolog.handler to the Monolog handler stack.
config/packages/monolog.yaml
monolog:
  handlers:
    # other handlers

    appsignal:
      type: service
      id: appsignal.monolog.handler
      channels: ["app", "event"] # configure which channels to send to AppSignal

Monolog

Monolog is the most popular logging library for PHP. You can use Monolog directly to send logs to AppSignal. Install the Monolog auto-instrumentation package.
Shell
composer require open-telemetry/opentelemetry-logger-monolog
Then add Appsignal\Integrations\Monolog\Handler to Monolog’s handler stack.
PHP
use Appsignal\Integrations\Monolog\Handler;
use Monolog\Logger;

$logger = new Logger('app');
$logger->pushHandler(Handler::withLevel('info'));

$logger->info('My log message');

Stand-alone usage

You can also send logs with the stand-alone logger using the log helper method from the Appsignal base class. This method doesn’t require configuration.
PHP
use Appsignal\Appsignal;
use Appsignal\Severity;

// Log a message
Appsignal::log(
	message: 'Log message line',
	severity: Severity::INFO,
	loggerName: 'my-app',
	attributes: [
		'customer_id' => $customer->id,
	],
);
Configure Monolog with the OpenTelemetry handler to send logs to AppSignal:
PHP
use Appsignal\Integrations\Monolog\Handler;
use Monolog\Logger;

// Create Monolog logger with the AppSignal handler
$logger = new Logger('app', [Handler::withLevel('info')]);

Sending logs

Monolog

Using Monolog, you can define the severity level of your logs:
PHP
$logger->warning("Something's gone terribly wrong here");
$logger->info('User action completed successfully');
$logger->error('Database connection failed');

// using Laravel's Log facade
Log::warning("Something's gone terribly wrong here");
Log::info('User action completed successfully');
Log::error('Database connection failed');
You can define custom attributes to send log information that can be used when filtering and querying logs:
PHP
$logger->info('Generating invoice for customer', ['customer_id' => $customer->id]);

// using Laravel's Log facade
Log::info('Generating invoice for customer', ['customer_id' => $customer->id]);

Stand-alone logger

Using the stand-alone logger, you can define the severity level of your logs:
PHP
use Appsignal\Appsignal;
use Appsignal\Severity;

// Different severity levels
Appsignal::log(
	message: "Something's gone terribly wrong here",
	severity: Severity::WARN,
);

Appsignal::log(
	message: 'User action completed successfully',
	severity: Severity::INFO,
);

Appsignal::log(
	message: 'Database connection failed',
	severity: Severity::ERROR,
);
You can define custom attributes to send log information that can be used when filtering and querying logs:
PHP
use Appsignal\Appsignal;
use Appsignal\Severity;

function processInvoice($customer) {
	Appsignal::log(
		message: 'Generating invoice for customer',
		severity: Severity::INFO,
		attributes: ['customer_id' => $customer->id],
	);
}

Filtering logs

You can query and filter on message contents and attribute values from within the Log Management tool. Once configured, the desired attributes will be sent to AppSignal as log tags, and be queryable in the AppSignal logging interface.

Structured logging

AppSignal supports structured logging out of the box. You can send structured data as log attributes:
PHP
use Appsignal\Appsignal;
use Appsignal\Severity;

Appsignal::log(
	message: 'User action completed',
	severity: Severity::INFO,
    attributes: [
		'user_id' => $userId,
		'action' => 'purchase',
		'product_id' => $productId,
		'amount' => $amount,
		'currency' => 'USD'
	],
);

// or using Monolog
$logger->info('Generating invoice for customer', ['customer_id' => $customer->id]);

// or using Laravel's Log facade
Log::info('Generating invoice for customer', ['customer_id' => $customer->id]);
You can also configure AppSignal for PHP to ignore specific log lines using the ignore_logs option. See our Ignore Logs guide to learn more.

Need help?

After configuring your PHP application to send logs, logs should appear in AppSignal. If you are unsure about this step or AppSignal is not receiving any logs, you can always reach out for assistance. We’ll help get you back on track!