Better Stack PHP logging

Start logging in 3 steps

Collect logs from any PHP code, including Laravel or Symfony.

1. Install

Install Better Stack PHP client library:

Monolog v3 Monolog v2
composer require logtail/monolog-logtail
composer require logtail/monolog-logtail:^2.0.0

2. Setup

Set up Monolog logger with Better Stack:

Set up Logtail handler
require "../vendor/autoload.php";

use Monolog\Logger;
use Logtail\Monolog\LogtailHandler;

$logger = new Logger("example-app");
$handler = LogtailHandlerBuilder::withSourceToken("$SOURCE_TOKEN")

3. Start logging ๐ŸŽ‰

Use Monolog logger as usual:

Send logs to Logtail
$logger->error("Something bad happened.");
$logger->info("Log message with structured logging.", [
    "item" => "Orange Soda",
    "price" => 100,

You should see your logs in Logtail โ†’ Live tail.

PHP version 8 or higher is required.
Composer version 1.10.1 or higher is required.

Need help?

Please let us know at
We're happy to help! ๐Ÿ™

Additional information

New to logging?

Check out our Intro guide to Logging in PHP.

Using Laravel?

Explore our Guide to Logging in Laravel.

Using Symfony?

After installing logtail/monolog-logtail package, you can set up logging to Better Stack by registering two services in your services.yaml and providing a BETTER_STACK_SOURCE_TOKEN environment variable:

    # ...

        autoconfigure: true
            $sourceToken: '%env(BETTER_STACK_SOURCE_TOKEN)%'
            - { name: monolog.handler }

    # optional processor to replace context variables in your logs
    # e.g. replaces {route} by context.route
        autoconfigure: true
            - { name: monolog.processor }

Logging from console scripts?

By default, PHP doesn't trigger shutdown handlers when the script is terminated via CTRL+C. To make sure your logs will get updated after interrupt, register the following signal handler:

Ensure logs are uploaded after script termination via CTRL+C
pcntl_signal(SIGINT, function() {

Example project

Want to try a runnable example?
See our PHP Logs example project on GitHub.