1. Go to this page and download the library: Download super-kernel/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/ */
super-kernel / logger example snippets
declare(strict_types=1);
namespace Src\Config\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use SuperKernel\Attribute\Configuration;
use SuperKernel\Logger\Contract\LoggerConfigInterface;
#[Configuration(LoggerConfigInterface::class)]
final class LoggerConfig implements LoggerConfigInterface
{
public array $default = [
'handler' => [
'class' => StreamHandler::class,
'constructor' => [
'stream' => 'logs/default.log',
'level' => Level::Debug,
],
],
'formatter' => [
'class' => LineFormatter::class,
'constructor' => [
'format' => null,
'dateFormat' => null,
'allowInlineLineBreaks' => true,
],
],
];
}
declare(strict_types=1);
namespace Src\Service;
use Psr\Log\LoggerInterface;
final class DemoService
{
public function __construct(private readonly LoggerInterface $logger)
{
}
public function method()
{
$this->logger->info('Application started');
$this->logger->error('Something went wrong');
}
}
declare(strict_types=1);
namespace Src\Service;
use Psr\Log\LoggerInterface;
final class DemoService
{
private readonly LoggerInterface $logger;
public function __construct(LoggerFactoryInterface $loggerFactory)
{
$this->logger = $loggerFactory->get('default');
}
public function method()
{
$this->logger->info('Application started');
$this->logger->error('Something went wrong');
}
}
declare(strict_types=1);
namespace Src\Provider;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Stringable;
use SuperKernel\Attribute\Factory;
use SuperKernel\Attribute\Provider;
use Symfony\Component\Console\Output\ConsoleOutput;
#[
Provider(class: LoggerInterface::class, priority: 2),
Factory,
]
final class Logger implements LoggerInterface
{
public function __invoke(LoggerFactoryInterface $loggerFactory): LoggerInterface
{
return $loggerFactory->get('your logger name');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.