PHPackages                             marceli-to/wiretap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. marceli-to/wiretap

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

marceli-to/wiretap
==================

A simplified logging package for Laravel with webhook capabilities

v1.4.0(9mo ago)032MITPHPPHP ^8.0

Since Sep 18Pushed 9mo agoCompare

[ Source](https://github.com/marceli-to/wiretap-package)[ Packagist](https://packagist.org/packages/marceli-to/wiretap)[ RSS](/packages/marceli-to-wiretap/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (6)Used By (0)

Wiretap Package - Laravel Logging with Webhook Support
======================================================

[](#wiretap-package---laravel-logging-with-webhook-support)

A Laravel package for centralized logging with webhook capabilities to send structured logs to external dashboards.

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require marceli-to/wiretap
```

### 2. Publish Configuration (Optional)

[](#2-publish-configuration-optional)

```
php artisan vendor:publish --provider="MarceliTo\Wiretap\Providers\WiretapServiceProvider"
```

This will create `config/wiretap.php` with configuration options.

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Add these variables to your `.env` file:

```
# Master switch to enable/disable all Wiretap functionality
WIRETAP_ENABLED=true

# Enable webhook functionality
WIRETAP_WEBHOOK_ENABLED=true

# Your Wiretap dashboard webhook URL
WIRETAP_WEBHOOK_URL=https://your-wiretap-dashboard.com/api/webhook/logs

# Webhook authentication secret (highly recommended)
WIRETAP_WEBHOOK_SECRET=your-secret-key-here

# Application name (will appear in dashboard)
WIRETAP_APP_NAME="Your Application Name"

# Optional: Also log to Laravel's default log files
WIRETAP_LARAVEL_ENABLED=true

# Optional: Log webhook failures to Laravel logs
WIRETAP_WEBHOOK_LOG_FAILURES=true

# Optional: HTTP timeout for webhook requests (seconds)
WIRETAP_TIMEOUT=10
```

### Webhook Authentication

[](#webhook-authentication)

For webhook authentication, the package supports Bearer token authentication via the `WIRETAP_WEBHOOK_SECRET` environment variable (recommended approach):

```
WIRETAP_WEBHOOK_SECRET=your-secret-key-here
```

This automatically adds the `Authorization: Bearer your-secret-key-here` header to all webhook requests.

### Custom Headers (Advanced)

[](#custom-headers-advanced)

For additional headers beyond authentication, edit `config/wiretap.php`:

```
'webhook' => [
    'headers' => [
        'X-API-Key' => env('WIRETAP_API_KEY'),
        'X-Custom-Header' => 'custom-value',
    ],
],
```

Then add to `.env`:

```
WIRETAP_API_KEY=your-additional-api-key
```

**Note:** If you configure both `WIRETAP_WEBHOOK_SECRET` and custom `Authorization` header, the webhook secret takes precedence.

Usage
-----

[](#usage)

### Basic Logging

[](#basic-logging)

```
use MarceliTo\Wiretap\Facades\Wiretap;

// Log levels
Wiretap::info('User logged in', ['user_id' => 123]);
Wiretap::error('Database connection failed', ['error' => $exception->getMessage()]);
Wiretap::warning('Low disk space detected', ['available' => '2GB']);
Wiretap::debug('Cache miss', ['key' => 'user:123']);

// Custom log level
Wiretap::log('custom', 'Custom event occurred', ['data' => $someData]);
```

### In Controllers

[](#in-controllers)

```
class UserController extends Controller
{
    public function store(Request $request)
    {
        try {
            $user = User::create($request->validated());

            Wiretap::info('New user registered', [
                'user_id' => $user->id,
                'email' => $user->email,
                'ip' => $request->ip(),
                'user_agent' => $request->userAgent()
            ]);

            return response()->json($user, 201);
        } catch (\Exception $e) {
            Wiretap::error('User registration failed', [
                'error' => $e->getMessage(),
                'input' => $request->except(['password']),
                'trace' => $e->getTraceAsString()
            ]);

            throw $e;
        }
    }
}
```

### Exception Handling

[](#exception-handling)

Wiretap includes smart exception filtering to reduce noise from expected exceptions like validation errors, 404s, and authentication failures.

#### Smart Exception Logging (Recommended)

[](#smart-exception-logging-recommended)

Add to `app/Exceptions/Handler.php`:

```
