Explore documentation
Installing Logtail PHP client
Logtail allows you to collect logs directly from PHP projects, including Laravel, Symfony, CodeIgniter, CakePHP, Zend, and others. Supported versions are:
- PHP 8 or newer
- Composer 1.10.1 or newer
Installing Logtail PHP client
Install the Logtail PHP client library using Composer:
composer require logtail/monolog-logtail
Adding Logtail to existing PHP project
Already have a PHP project you want to add logtail to? To add Logtail client library to existing project, run the following command:
composer require logtail/monolog-logtail
You can find more about basic composer usage in the official guide .
How it works in action
Here is an example of how to send logs from your PHP application to Logtail.
For a more detailed example, please see the PHP + Logtail example project on GitHub .
Example: Snippet added to your app
<?php
require "vendor/autoload.php";
use Monolog/Logger;
use Logtail/Monolog/LogtailHandler;
$logger = new Logger("example-app");
$logger->pushHandler(new LogtailHandler("<source-token>"));
$logger->info("logtail integration is ready");
$logger->warn("log structured data", [
"item" => [
"url" => "https://fictional-store.com/item-123",
"price" => 100
]
]);
Example: JSON rows sent to Logtail
{
"dt": "2021-03-29T11:24:54.788Z",
"level": "info",
"message": "logtail integration is ready",
"monolog": {
"channel": "example-app"
}
}
{
"dt": "2021-03-29T11:24:54.788Z",
"level": "warn",
"message": "log structured data",
"monolog": {
"channel": "example-app",
"context": {
"item": {
"url": "https://fictional-store.com/item-123",
"price": 100
}
}
}
}