1. Go to this page and download the library: Download logdash/php-sdk 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/ */
logdash / php-sdk example snippets
ogdash\Logdash;
// Create Logdash instance without API key for local logging only
$logdash = Logdash::create();
$logger = $logdash->logger();
// Log different levels
$logger->error('This is an error message');
$logger->warn('This is a warning message');
$logger->info('This is an info message');
$logger->debug('This is a debug message');
ogdash\Logdash;
// Create Logdash instance with API key for cloud sync
$logdash = Logdash::create([
'apiKey' => 'your-api-key-here',
'host' => 'https://api.logdash.io', // Optional, defaults to this
'verbose' => true // Optional, for debugging
]);
$logger = $logdash->logger();
$metrics = $logdash->metrics();
// Logging with cloud sync
$logger->error('Application error occurred');
$logger->info('User logged in successfully');
// Custom metrics
$metrics->set('active_users', 150);
$metrics->mutate('login_count', 1); // Increment by 1
$metrics->mutate('error_count', -1); // Decrement by 1
// In your AppServiceProvider or custom service provider
use Logdash\Logdash;
public function register()
{
$this->app->singleton('logdash', function ($app) {
return Logdash::create([
'apiKey' => config('services.logdash.api_key'),
'verbose' => config('app.debug')
]);
});
}
// Usage in controllers/services
public function someMethod()
{
$logdash = app('logdash');
$logdash->logger()->info('Operation completed');
$logdash->metrics()->set('operation_count', 42);
}
// In your services.yaml
services:
logdash:
class: Logdash\Logdash
factory: ['Logdash\Logdash', 'create']
arguments:
- apiKey: '%env(LOGDASH_API_KEY)%'
verbose: '%kernel.debug%'
// Usage in controllers/services
public function someAction(Logdash $logdash)
{
$logdash->logger()->info('Action executed');
$logdash->metrics()->mutate('action_count', 1);
}