1. Go to this page and download the library: Download solophp/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/ */
solophp / logger example snippets
use Psr\Log\LogLevel;
use Solo\Logger\Logger;
// Initialize logger
$logger = new Logger('/path/to/log/file.log');
// Log messages
$logger->info('Application started');
$logger->error('Failed to charge user {user_id}', ['user_id' => 42, 'error_code' => 500]);
// Only WARNING and above will be written
$logger->setMinLevel(LogLevel::WARNING);
$logger = new Logger('/path/to/log/file.log', 'America/New_York');
$logger = new Logger(
'logs/combined.log',
'',
2 * 1024 * 1024, // 2MB limit
20, // 20 files max
'both', // both size and time
6 * 3600 // 6 hours
);
use Solo\Logger\Formatter\JsonFormatter;
use Solo\Logger\Formatter\LineFormatter;
use Solo\Logger\Formatter\LogfmtFormatter;
use Solo\Logger\Logger;
// Via constructor (last argument)
$logger = new Logger('app.log', '', 0, 0, 'size', 86400, new JsonFormatter());
// Or swap at runtime
$logger->setFormatter(new LogfmtFormatter());
// Defaults: template = "[{time}] {level}: {message}", date format = DateTimeInterface::ATOM
$formatter = new LineFormatter(
template: '{time} [{level}] {message}',
dateFormat: 'Y-m-d H:i:s',
);
use Solo\Logger\Formatter\FormatterInterface;
final class MyFormatter implements FormatterInterface
{
public function format(string $level, string|\Stringable $message, array $context, \DateTimeInterface $time): string
{
return sprintf('%s %s %s', $time->format('c'), strtoupper($level), $message);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.