PHP code example of czernika / orchid-log-viewer

1. Go to this page and download the library: Download czernika/orchid-log-viewer 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/ */

    

czernika / orchid-log-viewer example snippets


use Czernika\OrchidLogViewer\Screen\OrchidLogListScreen;

class CustomLogListScreen extends OrchidLogListScreen
{
    // Change logic
}

use Czernika\OrchidLogViewer\LogManager;

public function boot()
{
    LogManager::useScreen(CustomLogListScreen::class);
}

use Czernika\OrchidLogViewer\Layouts\OrchidLogTableLayout;

class CustomLogTableLayout extends OrchidLogTableLayout
{
    // Change logic
}

use Czernika\OrchidLogViewer\LogManager;

public function boot()
{
    LogManager::useLayout(CustomLogTableLayout::class);
}

public function columns(): iterable
{
    return [
        $this->levelColumn(), // Level icon with level name
        $this->textColumn(), // Log message text (70% table wide)
        $this->stackTraceColumn(), // Stack trace modal button
        $this->dateColumn(), // Date column
    ];
}

[
    'text' => '',
    'context' => '',
    'level' => '',
    'level_class' => '',
    'level_img' => '',
    'folder' => '',
    'in_file' => '',
    'date' => '',
]

$log->text();
$log->levelClass();

// etc

TD::make('text', 'Text'),

// instead of

TD::make('text', 'Text')
    ->render(fn (array $log) => $log['text']),

use Czernika\OrchidLogViewer\LogData;

class CustomLogData extends LogData
{
    public function areWeGood(): bool
    {
        return 'error' === $this->data['level'] ? 'Nope' : 'Sure we are';
    }
}

use Czernika\OrchidLogViewer\LogManager;

public function boot()
{
    LogManager::useMapper(CustomLogData::class);
}

TD::make('are_we_good')
    ->render(fn (LogData $log) => $log->areWeGood()),

use Czernika\OrchidLogViewer\Support\Traits\Contentable;

class CustomLogData
{
    use Contentable;

    public function __construct(
        protected readonly array $data,
    ) {}

    public function areWeGood(): bool
    {
        return 'error' === $this->data['level'] ? 'Nope' : 'Sure we are';
    }
}

TD::make('areWeGood'), // pass name in a exact case as method in a custom class (not `are_we_good`)

use Czernika\OrchidLogViewer\LogManager;

public function boot()
{
    LogManager::clearLogFileUsing(CustomClearLogFileAction::class);
    LogManager::deleteLogFileUsing(CustomDeleteLogFileAction::class);
}

use Czernika\OrchidLogViewer\Contracts\HandlesLogs;
use Czernika\OrchidLogViewer\Contracts\LogServiceContract;

public function handle(LogServiceContract $logService, string $file): void
{
    // ...
}
sh
php artisan vendor:publish --provider="Czernika\OrchidLogViewer\OrchidLogServiceProvider"