PHP code example of tobento / app-logging-web

1. Go to this page and download the library: Download tobento/app-logging-web 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/ */

    

tobento / app-logging-web example snippets


use Tobento\App\AppFactory;
use Tobento\App\Logging\Web\LogRepositoryInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Logging\Web\Boot\LoggingWeb::class);
$app->booting();

// Implemented interfaces:
$logRepository = $app->get(LogRepositoryInterface::class);

// Run the app
$app->run();

'features' => [
    new Feature\Logs(
        // A menu name to show the logs link, or null for no menu entry.
        menu: 'main',
        menuLabel: 'Logs',
        // A menu parent name (e.g. 'system') or null if none.
        menuParent: null,
        
        // You may disable ACL while testing.
        // Otherwise, only users with the 

use Tobento\App\Card\CardsInterface;

'features' => [
    new Feature\LogsCards(
        // Define the card collections where the logs cards should be added.
        applyToCards: [
            \Tobento\App\Backend\Card\DashboardCards::class, // CardsInterface
        ],
        
        // You may disable ACL while testing.
        // Otherwise, only users with the 

use Tobento\App\Card\CardsInterface;
use Tobento\App\Logging\Web\Card\LatestLogsCard;
use Tobento\App\Logging\Web\Feature\LogsCards;

class CustomLogsCards extends LogsCards
{
    protected function configureCards(AppInterface $app): CardsInterface
    {
        $cards = parent::configureCards(app: $app);
        
        // Example: Add a custom card showing the latest debug logs.
        $cards->add('latest-debug-logs', new LatestLogsCard(
            logRepository: $app->container()->get(LogRepositoryInterface::class),
            view: $app->container()->get(ViewInterface::class),
            priority: 1000,
            title: 'Latest Debug Logs',
            levels: ['debug'],
            limit: 5,
        ));

        return $cards;
    }
}

'features' => [
    new CustomLogsCards(
        applyToCards: [
            \Tobento\App\Backend\Card\DashboardCards::class,
        ],
        withAcl: true,
    ),
],

'features' => [
    new Feature\MonitorLogs(
        // Optionally override monitoring settings for specific loggers.
        // All other loggers are still monitored using their default settings.
        // To disable monitoring for a logger, you must explicitly configure it here.
        monitor: [
            'daily' => [
                'repository' => true, // write logs to LogRepositoryInterface (default)
                'logger' => true, // also log using the original logger (default)
            ],
        ],
    ),
],

use Tobento\Service\Schedule\Task;
use Butschster\CronExpression\Generator;

$schedule->task(
    new Task\CommandTask(
        command: 'logs:purge',
    )
    // Schedule task:
    ->cron(Generator::create()->daily())
);

'features' => [
    Feature\Logs::class,
    Feature\MonitorLogs::class,
],

'interfaces' => [
    LogRepositoryInterface::class =>
    static function(DatabasesInterface $databases): LogRepositoryInterface {
        return new LogStorageRepository(
            storage: $databases->default('shared:storage')->storage()->new(),
            table: 'logs',
        );
    },
],

'features' => [
    // only monitor logs:
    Feature\MonitorLogs::class,
],

'interfaces' => [
    LogRepositoryInterface::class =>
    static function(DatabasesInterface $databases): LogRepositoryInterface {
        return new LogStorageRepository(
            storage: $databases->default('shared:storage')->storage()->new(),
            table: 'logs',
        );
    },
],

'defaults' => [
    'pdo' => 'mysql',
    'storage' => 'file',
    'shared:storage' => 'shared:file',
],

'databases' => [
    'shared:file' => [
        'factory' => \Tobento\Service\Database\Storage\StorageDatabaseFactory::class,
        'config' => [
            'storage' => \Tobento\Service\Storage\JsonFileStorage::class,
            'dir' => directory('app:parent').'storage/database/file/',
        ],
    ],
],

php ap logs:purge