This guide will help you get started with the Logdash PHP SDK in under 5 minutes.
- PHP 8.1 or higher
- Composer
-
Install the package via Composer:
composer require logdash/php-sdk
-
Create your first Logdash instance:
<?php require_once 'vendor/autoload.php'; use Logdash\Logdash; // For local logging only $logdash = Logdash::create(); $logger = $logdash->logger(); $logger->info('Hello, Logdash!');
-
Add cloud synchronization (optional):
- Get your API key from logdash.io
- Update your code:
$logdash = Logdash::create([ 'apiKey' => 'your-api-key-here' ]);
Add to your AppServiceProvider:
use Logdash\Logdash;
public function register()
{
$this->app->singleton('logdash', function () {
return Logdash::create([
'apiKey' => config('services.logdash.api_key'),
'verbose' => config('app.debug')
]);
});
}Add to config/services.php:
'logdash' => [
'api_key' => env('LOGDASH_API_KEY'),
],Usage in controllers:
public function store(Request $request)
{
$logdash = app('logdash');
$logdash->logger()->info('Creating new record');
$logdash->metrics()->mutate('records_created', 1);
// Your logic here...
}Add to config/services.yaml:
services:
logdash:
class: Logdash\Logdash
factory: ['Logdash\Logdash', "create"]
arguments:
- apiKey: "%env(LOGDASH_API_KEY)%"
verbose: "%kernel.debug%"Usage in controllers:
use Logdash\Logdash;
class MyController extends AbstractController
{
public function index(Logdash $logdash): Response
{
$logdash->logger()->info('Controller action executed');
$logdash->metrics()->set('page_views', 42);
return $this->render('template.html.twig');
}
}Create a .env file:
LOGDASH_API_KEY=your-api-key-here
LOGDASH_HOST=https://api.logdash.io
LOGDASH_VERBOSE=falseRun the examples:
php examples.phpRun the test script:
php test.php- Explore the examples.php file for more usage patterns
- Check out the full documentation
- Visit logdash.io to set up your project dashboard
- No output when logging: Make sure you're calling the logger methods correctly
- API errors: Check your API key and network connectivity
- Composer autoload issues: Run
composer dump-autoload
For more help, visit docs.logdash.io or contact support.