Skip to content

Latest commit

 

History

History
150 lines (108 loc) · 2.76 KB

File metadata and controls

150 lines (108 loc) · 2.76 KB

Quick Setup Guide

This guide will help you get started with the Logdash PHP SDK in under 5 minutes.

Prerequisites

  • PHP 8.1 or higher
  • Composer

Installation

  1. Install the package via Composer:

    composer require logdash/php-sdk
  2. 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!');
  3. Add cloud synchronization (optional):

    • Get your API key from logdash.io
    • Update your code:
    $logdash = Logdash::create([
        'apiKey' => 'your-api-key-here'
    ]);

Framework Integration

Laravel

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...
}

Symfony

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');
    }
}

Environment Variables

Create a .env file:

LOGDASH_API_KEY=your-api-key-here
LOGDASH_HOST=https://api.logdash.io
LOGDASH_VERBOSE=false

Testing

Run the examples:

php examples.php

Run the test script:

php test.php

Next Steps

  1. Explore the examples.php file for more usage patterns
  2. Check out the full documentation
  3. Visit logdash.io to set up your project dashboard

Troubleshooting

  • 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.