1. Go to this page and download the library: Download initphp/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/ */
initphp / logger example snippets
use InitPHP\Logger\FileLogger;
use InitPHP\Logger\Logger;
$logger = new Logger(
new FileLogger(['path' => __DIR__ . '/logs/app.log'])
);
$logger->info('Service booted in {ms}ms', ['ms' => 42]);
$logger->error('Payment {id} failed', ['id' => 9182]);
use InitPHP\Logger\FileLogger;
$logger = new FileLogger([
'path' => __DIR__ . '/logs/app-{year}-{month}-{day}.log',
]);
use InitPHP\Logger\PDOLogger;
$pdo = new PDO('mysql:host=localhost;dbname=app;charset=utf8mb4', 'app', 'secret');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$logger = new PDOLogger(['pdo' => $pdo, 'table' => 'logs']);
$logger->error('User {user} caused an error.', ['user' => 'muhammetsafak']);
// INSERT INTO logs (level, message, date) VALUES ('ERROR', 'User muhammetsafak caused an error.', '2026-05-24 14:08:22')
use InitPHP\Logger\FileLogger;
use InitPHP\Logger\Logger;
use InitPHP\Logger\PDOLogger;
$logger = new Logger(
new FileLogger(['path' => __DIR__ . '/logs/app.log']),
new PDOLogger(['pdo' => $pdo, 'table' => 'logs'])
);
$logger->warning('cache miss for key {key}', ['key' => 'user:42']);
// Goes to BOTH the file and the database table.