# Laravel logging: ship logs and exceptions to Tailcove

By the end of this guide every `Log::` call and every reported exception in your Laravel app will land in Tailcove, batched off the request's critical path, with request ids and user ids attached automatically.

The quickest way is two commands, which do steps 1 to 3 for you and send a test line:

```bash
composer require tailcove/laravel
php artisan tailcove:install
```

`tailcove:install` opens Tailcove in your browser to approve a new source, then writes the tokens to `.env`. The steps below do the same by hand.

## 1. Create a source and copy its token

In Tailcove, open **Sources** and click **New source**. Name it after the app and environment, for example `shop-production`, and pick **Laravel** as the platform so the setup snippets match.

The ingest token is shown **once**. Copy it now: Tailcove only stores a hash, so if you lose it you will need to rotate it.

![Creating a Laravel source named shop-staging: Sources, New source, Laravel, a name, Create source, and the token shown once](https://tailcove.dev/images/guides/laravel-logging/create-source.mp4 "Sources, New source, Laravel, a name, and keep the default retention. The token appears on the next page, once.")

## 2. Install the package

```bash
composer require tailcove/laravel
```

![composer require tailcove/laravel installing the package](https://tailcove.dev/images/guides/laravel-logging/install.mp4 "Composer adds the package; auto-discovery registers it, so there's nothing else to wire up.")

Package auto-discovery registers the service provider. Add your token to `.env`:

```env
TAILCOVE_TOKEN=your-source-ingest-token
```

## 3. Add the channel

Register a `tailcove` channel in `config/logging.php`:

```php
'channels' => [
    // ...
    'tailcove' => [
        'driver' => 'tailcove',
        'level' => env('LOG_LEVEL', 'debug'),
    ],
],
```

Then add it to your log stack, keeping your local file log alongside it:

```env
LOG_STACK=single,tailcove
```

## 4. Log with context

Keep the message constant and put the details in context, so every occurrence is the same searchable event:

```php
use Illuminate\Support\Facades\Log;

Log::info('Order placed', ['order_id' => $order->id, 'total_cents' => $order->total]);

Log::warning('Payment retry', ['order_id' => $order->id, 'attempt' => 2]);
```

Every line also gets `environment`, `hostname`, `user_id` (when someone is signed in) and a `request_id` shared by all lines from the same request, so you can follow a single request end to end.

## 5. Report exceptions

Laravel's exception handler already logs unhandled exceptions through your stack. For handled ones, pass the exception in context or call `report()`:

```php
try {
    $gateway->charge($order);
} catch (CardDeclined $e) {
    Log::error('Payment failed', ['order_id' => $order->id, 'exception' => $e]);
}
```

The exception is sent as structured data (class, message, location and trace), which is what lets Tailcove group repeats into a single **issue**.

## 6. Verify it works

Open the source in Tailcove and switch to **Live tail**, then trigger a log line:

```bash
php artisan tinker --execute 'Log::info("Hello from Laravel");'
```

![Live tail on shop-production: "Hello from Laravel" arrives, then two more lines](https://tailcove.dev/images/guides/laravel-logging/live-tail.mp4 "Live tail picks up each line as it's stored, usually within a second or two.")

The line appears within a second or two. If nothing shows up, check that `TAILCOVE_TOKEN` is set in the environment the process actually runs with (queue workers and Horizon read their own environment).

## 7. Turn on extra telemetry (optional)

The package can also ship slow queries, failed queue jobs and failed scheduled tasks, each off by default:

```env
TAILCOVE_LOG_SLOW_QUERIES=true
TAILCOVE_SLOW_QUERY_THRESHOLD_MS=500
TAILCOVE_LOG_FAILED_JOBS=true
TAILCOVE_LOG_SCHEDULE_FAILURES=true
```

## Secrets are masked before they leave

From v0.2.0 the package masks passwords, tokens and API keys in your app before a line is buffered: a context key like `password` or `api_key` becomes `[redacted]`, and so does the value after `token=` or `Authorization: Bearer` in a message. It's on by default, so `Log::info('Login', ['password' => $request->password])` never sends the password. Add your own field names with `TAILCOVE_SECRET_KEYS=customer_ssn,iban`, and use `Tailcove::beforeSend()` to change or drop lines yourself. Details are in the [package reference](https://tailcove.dev/docs/sending-logs/laravel-package#secret-masking).

## How delivery works

Records are buffered in memory and sent as one batch every 50 records or 2 seconds. By default the batch goes out from a shutdown function, after the response has been sent. To move delivery onto your queue instead:

```env
TAILCOVE_DISPATCH=queue
TAILCOVE_QUEUE_CONNECTION=redis
```

In queue workers (`queue:work`, Horizon) the buffered lines are also sent after every job, and under Octane after every request, so a long-running process never holds them until it restarts.

A delivery failure never throws into your app; it falls back to PHP's `error_log()`.

## Next steps

- Learn the [query language](https://tailcove.dev/docs/query-language) to search by any context field.
- [Alert on 5xx spikes](https://tailcove.dev/guides/alert-on-error-spikes) so you hear about problems first.
- See every option in the [Laravel package reference](https://tailcove.dev/docs/sending-logs/laravel-package).
