#9 Logger setup
All checks were successful
Build and test. / build (push) Successful in 18s
Build and test. / test (push) Successful in 16s
Build and test. / cleanup (push) Successful in 5s

This commit is contained in:
Chicory 2025-08-27 13:03:50 +03:00
parent 21e254bfbc
commit 8ef5bd0c49
Signed by untrusted user who does not match committer: chicory
GPG Key ID: AC95A793F70BEDCD
7 changed files with 46 additions and 8 deletions

3
.gitignore vendored
View File

@ -10,3 +10,6 @@ composer.lock
/var/cache/*
!/var/cache/.gitkeep
# Logs
/var/log/*
!/var/log/.gitkeep

View File

@ -14,7 +14,8 @@
"nyholm/psr7": "^1.8",
"nyholm/psr7-server": "^1.1",
"guzzlehttp/psr7": "^2",
"php-di/slim-bridge": "^3.4"
"php-di/slim-bridge": "^3.4",
"monolog/monolog": "^3.9"
},
"require-dev": {
"phpstan/phpstan": "^2.1",

View File

@ -19,8 +19,8 @@ return $config
'ternary_to_null_coalescing' => true,
'concat_space' => ['spacing' => 'one'],
])
->setCacheFile('/app/var/cache/php-cs-fixer.cache')
->setCacheFile(__DIR__ . '/../var/cache/php-cs-fixer.cache')
->setFinder(PhpCsFixer\Finder::create()
->in('/app/src')
->in('/app/tests')
->in(__DIR__ . '/../src')
->in(__DIR__ . '/../tests')
);

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="../vendor/autoload.php"
colors="true"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="../vendor/autoload.php"
cacheResultFile="../var/cache/phpunit.cache"
colors="true"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">/app/tests</directory>
<directory suffix="Test.php">../tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -3,12 +3,22 @@
declare(strict_types=1);
use DI\Bridge\Slim\Bridge;
use DI\Container;
use DI\ContainerBuilder;
use Psr\Container\ContainerInterface;
use Slim\App;
return function (): App {
$containerBuilder = new ContainerBuilder();
/**
* Bind dependencies.
*
* @var callable(ContainerBuilder<Container>):void $dependencies
* */
$dependencies = require __DIR__ . '/dependencies.php';
$dependencies($containerBuilder);
$container = $containerBuilder->build();
/** @var App<ContainerInterface> $app */

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
use DI\ContainerBuilder;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Monolog\Processor\UidProcessor;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
return function (ContainerBuilder $builder): void {
$builder->addDefinitions([
LoggerInterface::class => function (ContainerInterface $container) {
$logger = new Logger('app');
$logger->pushProcessor(new UidProcessor());
$logger->pushHandler(new RotatingFileHandler(__DIR__ . '/../var/log/app.log', 7, Logger::WARNING));
return $logger;
},
]);
};

0
var/log/.gitkeep Normal file
View File