PHP code example of qubus / log

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

    

qubus / log example snippets


use Psr\Log\LogLevel;
use Qubus\Log\JsonFormat;
use Qubus\Log\Loggers\StreamLogger;

$logger = new StreamLogger('/var/log/app/application.log', LogLevel::INFO, [
    'logFormat' => new JsonFormat(),
]);
$logger->info('User {id} signed in', ['id' => 123]);
$logger->error('Request failed', ['exception' => $exception]);
$logger->close();

$console = new StreamLogger('php://stderr');
$console->warning('Queue is full');

use League\Flysystem\Filesystem;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Qubus\Log\Loggers\FileLogger;

$filesystem = new Filesystem(new LocalFilesystemAdapter(__DIR__ . '/logs'));
$logger = new FileLogger($filesystem, 'info');
$logger->info('Hello {name}', ['name' => 'world']);
// info-YYYY-MM-DD.log

use Qubus\Log\Loggers\MailerLogger;
use Qubus\Mail\QubusMailer;

// $config is your Qubus ConfigContainer with mailer.dsn configured.
$mailer = new QubusMailer($config);
$logger = new MailerLogger($mailer, 'error', [
    'from' => '[email protected]',
    'to' => ['[email protected]' => 'Operations'],
    'subject' => 'Application error',
    'encoding' => 'utf-8',
]);
$logger->error('Job {id} failed', ['id' => 42, 'exception' => $exception]);

use Qubus\Log\Loggers\DatabaseLogger;

$logger = new DatabaseLogger([
    'db' => $pdo,
    'table' => 'application_logs',
    'threshold' => 'warning',
]);
$logger->error('Payment {id} failed', ['id' => 123]);

use Qubus\Log\Logger;

$fileLogger->setThreshold('notice');
$fileLogger->enabled = false;
$logger = new Logger([$fileLogger, $mailLogger, $anotherPsrLogger]);
$logger->critical('Service unavailable');

use Qubus\Log\Context;
use Qubus\Log\JsonFormat;

$format = new JsonFormat(
    timezone: new DateTimeZone('UTC'),
    sensitiveKeys: [...Context::SENSITIVE_KEYS, 'email'],
);
$logger->setLogFormat($format);