PHP code example of mahmoud-mhamed / laravel-logman

1. Go to this page and download the library: Download mahmoud-mhamed/laravel-logman library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mahmoud-mhamed / laravel-logman example snippets


'telegram' => [
    'enabled' => true,
    ...
],

'discord' => [
    'enabled' => true,
    ...
],

'mail' => [
    'enabled' => true,
    ...
],

'slack' => ['enabled' => true, 'min_level' => 'debug', 'queue' => false, 'throttle' => 0],
'mail'  => ['enabled' => true, 'min_level' => 'critical', 'queue' => true, 'retries' => 1, 'throttle' => 60],

'request_logging' => [
    'enabled' => env('LOGMAN_REQUEST_LOGGING', false),
    'channel' => 'logman_requests',   // auto-created if not defined in config/logging.php
    'level' => 'info',

    'log_query' => true,              // query string params
    'log_body' => true,               // request body (masked)
    'log_headers' => true,            // curated set of request headers
    'log_response_status' => true,    // HTTP status code
    'log_response_body' => false,     // response body (masked; off by default)

    'middleware' => 'global',         // 'global' | 'web' | 'api' | ['web','api']

    // These three read from env as comma-separated lists (parsed into arrays):
    //   LOGMAN_REQUEST_METHODS="POST,PUT,DELETE"     → limit methods; empty = all
    //   LOGMAN_REQUEST_ONLY="api/*,checkout"         → path allowlist (* wildcards)
    //   LOGMAN_REQUEST_ONLY_CONTAINING="checkout"    → URL substring allowlist
    'methods' => [],
    'only' => [],
    'only_containing' => [],

    'body_ignore_methods' => ['GET', 'HEAD', 'OPTIONS'],

    'except' => ['telescope*', 'livewire*', '*.js', '*.css', /* ... */],
    'max_payload_length' => 8000,     // truncate oversized body/query payloads
],

// Logs the current request
logman_log_request();

// Log a specific request (and optionally its response)
logman_log_request($request);
logman_log_request($request, $response);

// Or via the facade
use MahmoudMhamed\Logman\Facades\Logman;

Logman::logRequest();          // current request
Logman::logRequest($request);  // a specific request

'viewer' => [
    'editor' => env('LOGMAN_EDITOR'),
    'editor_path_map' => [
        '/var/www/app' => '/Users/me/Code/app',
    ],
],

use MahmoudMhamed\Logman\Facades\Logman;

// Report an exception manually
try {
    // risky operation...
} catch (\Throwable $e) {
    Logman::logException($e);
}

// Send an info message to all enabled channels
Logman::sendInfo('Deployment completed successfully');

// Log the current HTTP request on demand (see "Request Logging" below).
// Bypasses the enabled switch and skip/allowlist filters.
logman_log_request();          // current request
Logman::logRequest($request);  // or a specific request

// config/logman.php
'ignore' => [
    \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class,
    \Illuminate\Auth\AuthenticationException::class,
    \Illuminate\Database\Eloquent\ModelNotFoundException::class,
],

// config/logman.php
'log_viewer' => [
    'middleware' => ['web', 'auth'],
    'authorize' => fn ($request) => $request->user()?->isAdmin(),
],

use MahmoudMhamed\Logman\Channels\ChannelInterface;

class PagerDutyChannel implements ChannelInterface
{
    public function sendException(array $payload): void { /* ... */ }
    public function sendInfo(string $message, array $context): void { /* ... */ }
}

use MahmoudMhamed\Logman\LogmanService;

LogmanService::registerDriver('pagerduty', PagerDutyChannel::class);

'channels' => [
    'pagerduty' => [
        'enabled' => true,
        'driver' => \App\Channels\PagerDutyChannel::class,
    ],
],

'daily_digest' => [
    'enabled' => true,
    'time'    => '09:00',  // 24h format, server timezone
],

'slack'    => ['enabled' => true,  'daily_digest' => true],   // gets the digest
'telegram' => ['enabled' => true,  'daily_digest' => false],  // no digest
'mail'     => ['enabled' => true,  'daily_digest' => true],   // gets the digest

// Laravel 11+
Schedule::command('logman:digest')->dailyAt('09:00');

// Laravel 10 and below (in Kernel.php)
$schedule->command('logman:digest')->dailyAt('09:00');
bash
php artisan logman:install
bash
php artisan logman:install --sync
bash
php artisan logman:test
bash
php artisan vendor:publish --tag=logman-config
bash
php artisan vendor:publish --tag=logman-config --force
bash
php artisan logman:install --sync
bash
php artisan vendor:publish --tag=logman-views