PHP code example of weijukeji / laravel-openobserve
1. Go to this page and download the library: Download weijukeji/laravel-openobserve 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/ */
weijukeji / laravel-openobserve example snippets
'channels' => [
// ... existing channels
'openobserve' => [
'driver' => 'custom',
'via' => \Weijukeji\LaravelOpenObserve\Logging\OpenObserveLogger::class,
'level' => env('LOG_LEVEL', 'debug'),
'name' => 'openobserve',
],
// Optionally add openobserve to a stack channel
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'openobserve'],
'ignore_exceptions' => false,
],
],
use Illuminate\Support\Facades\Log;
Log::info('User logged in', ['user_id' => 123]);
Log::error('An error occurred', ['error' => $exception->getMessage()]);
Log::warning('Warning message');
Log::debug('Debug information', ['data' => $debugData]);
use Weijukeji\LaravelOpenObserve\Facades\OpenObserve;
// Send a single log entry
OpenObserve::send([
'level' => 'info',
'message' => 'User action',
'user_id' => 123,
'action' => 'purchase',
]);
// Add to batch (automatically sent when batch size is reached)
OpenObserve::addToBatch([
'level' => 'info',
'message' => 'Event occurred',
]);
// Manually flush the batch
OpenObserve::flush();
use Weijukeji\LaravelOpenObserve\OpenObserveClient;
class SomeController extends Controller
{
public function __construct(
private OpenObserveClient $openObserve
) {}
public function index()
{
$this->openObserve->send([
'level' => 'info',
'message' => 'Controller executed',
'controller' => self::class,
]);
}
}
bash
php artisan vendor:publish --tag=openobserve-config
bash
php artisan openobserve:test