PHP code example of logtide / logtide-slim

1. Go to this page and download the library: Download logtide/logtide-slim 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/ */

    

logtide / logtide-slim example snippets


use LogTide\Slim\LogtideMiddleware;
use LogTide\Slim\LogtideErrorMiddleware;
use Slim\Factory\AppFactory;

// Initialize LogTide
\LogTide\init([
    'dsn' => 'https://[email protected]',
    'service' => 'my-slim-api',
]);

$app = AppFactory::create();

// Add LogTide request tracing middleware
$app->add(new LogtideMiddleware());

// Add routes
$app->get('/hello/{name}', function ($request, $response, $args) {
    $response->getBody()->write("Hello, {$args['name']}!");
    return $response;
});

// Option A: Use Slim's built-in error middleware (LogtideMiddleware captures errors too)
$app->addErrorMiddleware(true, true, true);

// Option B: Use LogtideErrorMiddleware as a standalone alternative
// $app->add(new LogtideErrorMiddleware($app->getResponseFactory()));

$app->run();

$middleware = new LogtideMiddleware(
    skipPaths: ['/health', '/healthz', '/metrics'],
);

use LogTide\Slim\LogtideErrorMiddleware;

// Use instead of $app->addErrorMiddleware()
$app->add(new LogtideErrorMiddleware(
    responseFactory: $app->getResponseFactory(),
    displayErrorDetails: true, // show details in dev
));