PHP code example of maidomax / laravel-datadog-logger

1. Go to this page and download the library: Download maidomax/laravel-datadog-logger 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/ */

    

maidomax / laravel-datadog-logger example snippets


'providers' => [
    // ...
    Maidomax\DatadogLogger\DatadogLoggerServiceProvider::class,
],

'channels' => [
    // ... other channels

    'datadog' => [
        'driver' => 'datadog',
        'api_key' => env('DATADOG_API_KEY'),
        'intake_url' => env('DATADOG_LOG_INTAKE_URL'),
        'service' => env('DATADOG_SERVICE'),
        'environment' => env('DATADOG_ENVIRONMENT'),
        'source' => env('DATADOG_SOURCE'),
        'timeout' => env('DATADOG_TIMEOUT', 5),
        'connection_timeout' => env('DATADOG_CONNECTION_TIMEOUT', 3),
    ],

    // Example: Use Datadog alongside other logging channels
    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'datadog'],
        'ignore_exceptions' => false,
    ],
],

use Illuminate\Support\Facades\Log;

// These will be sent to Datadog (and other configured channels)
Log::emergency('System is down!');
Log::alert('High CPU usage detected');
Log::critical('Database connection failed');
Log::error('User authentication failed', ['user_id' => 123]);
Log::warning('Deprecated API endpoint used');
Log::notice('User logged in', ['user_id' => 456]);
Log::info('Order processed successfully', ['order_id' => 789]);
Log::debug('Debug information', ['data' => $someData]);

// Using specific channel
Log::channel('datadog')->info('This goes directly to Datadog');

// With context
Log::info('User action performed', [
    'user_id' => 123,
    'action' => 'purchase',
    'amount' => 99.99,
    'ip_address' => request()->ip(),
]);
bash
php artisan vendor:publish --tag=datadog-logger-config