PHP code example of lane4hub / logger

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

    

lane4hub / logger example snippets


use Jardis\Logger\Logger;
use Jardis\Logger\command\LogFile;
use Jardis\Logger\command\LogConsole;
use Psr\Log\LogLevel;

$logger = new Logger('myDomain');
$logger->addHandler(new LogConsole(LogLevel::LOG_INFO));
$logger->addHandler(new LogFile(LogLevel::LOG_DEBUG, 'pathToLogFile'));

$logger->debug('This is a debug message', ['extra' => 'debug data']);
$logger->info('This is an info message');
$logger->error('An error occurred!', ['details' => 'error details']);

use Jardis\Logger\Logger;
use Jardis\Logger\command\LogConsole;
use Jardis\Logger\servic\format\LogJsonFormat;
use Psr\Log\LogLevel;

$logger = new Logger('myDomain');

$logConsole = (new LogConsole(LogLevel::LOG_INFO, 'pathToFile'))->setFormat(new LogJsonFormat());
$logger->addHandler($logConsole);

$logger->info('This is now logged in JSON format!', ['details' => 'info']);

use Jardis\Logger\command\LogFile;
use \Jardis\Logger\service\logData\LogClientIp;
use Jardis\Logger\Logger;
use Psr\Log\LogLevel;

$logger = new Logger('myDomain');

$logFile = (new LogFile(LogLevel::LOG_INFO, 'pathToFile'));
$logFile->logData()
    ->addUserLogData('client_ip', new LogClientIp())
    ->addUserLogData('test', fn() => 'value')
    ->addUserLogData('test', 'scalar value');

$logger->addHandler($logFile);

use Jardis\Logger\command\LogFile;
use \Jardis\Logger\service\logData\LogClientIp;
use Jardis\Logger\Logger;
use Psr\Log\LogLevel;

$logger = new Logger('myDomain');

$logFile = (new LogFile(LogLevel::LOG_INFO, 'pathToFile'));
$logFile->logData()
    ->addLogData('client_ip', new LogClientIp())
    ->addLogData('test', fn() => 'value')
    ->addLogData('test', 'scalar value');

$logger->addHandler($logFile);

use Jardis\Logger\Logger;
use Jardis\Logger\command\LogDatabase;
use Psr\Log\LogLevel;

$logger = new Logger('myDomain');

$logDatabase = (new LogDatabase(LogLevel::LOG_INFO, $yourPDO));
$logger->addHandler($logDatabase);

$logger->info('Log into database', ['details' => 'data']);