Merge pull request #558 from acelaya-forks/feature/monolog2

Feature/monolog2
This commit is contained in:
Alejandro Celaya 2019-11-30 18:22:44 +01:00 committed by GitHub
commit 8cc4d3e6d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 121 additions and 134 deletions

View file

@ -43,7 +43,8 @@ script:
after_success:
- rm -f build/clover.xml
- phpdbg -qrr vendor/bin/phpcov merge build --clover build/clover.xml
- wget https://phar.phpunit.de/phpcov-6.0.1.phar
- phpdbg -qrr phpcov-6.0.1.phar merge build --clover build/clover.xml
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover build/clover.xml

View file

@ -19,7 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
#### Changed
* *Nothing*
* [#492](https://github.com/shlinkio/shlink/issues/492) Updated to monolog 2, together with other dependencies, like Symfony 5 and infection-php.
#### Deprecated

View file

@ -28,20 +28,20 @@
"guzzlehttp/guzzle": "^6.3",
"lstrojny/functional-php": "^1.9",
"mikehaertl/phpwkhtmltopdf": "^2.2",
"monolog/monolog": "^1.24",
"monolog/monolog": "^2.0",
"nikolaposa/monolog-factory": "^3.0",
"ocramius/proxy-manager": "~2.2.2",
"phly/phly-event-dispatcher": "^1.0",
"predis/predis": "^1.1",
"pugx/shortid-php": "^0.5",
"shlinkio/shlink-common": "^2.3",
"shlinkio/shlink-event-dispatcher": "^1.0",
"shlinkio/shlink-installer": "^3.1",
"shlinkio/shlink-ip-geolocation": "^1.1",
"symfony/console": "^4.3",
"symfony/filesystem": "^4.3",
"symfony/lock": "^4.3",
"symfony/process": "^4.3",
"theorchard/monolog-cascade": "^0.5",
"shlinkio/shlink-common": "^2.4",
"shlinkio/shlink-event-dispatcher": "^1.1",
"shlinkio/shlink-installer": "^3.2",
"shlinkio/shlink-ip-geolocation": "^1.2",
"symfony/console": "^5.0",
"symfony/filesystem": "^5.0",
"symfony/lock": "^5.0",
"symfony/process": "^5.0",
"zendframework/zend-config": "^3.3",
"zendframework/zend-config-aggregator": "^1.1",
"zendframework/zend-diactoros": "^2.1.3",
@ -59,17 +59,14 @@
"require-dev": {
"devster/ubench": "^2.0",
"eaglewu/swoole-ide-helper": "dev-master",
"infection/infection": "^0.14.2",
"phpstan/phpstan": "^0.11.16",
"phpunit/phpcov": "^6.0",
"infection/infection": "^0.15.0",
"phpstan/phpstan-shim": "^0.11.16",
"phpunit/phpunit": "^8.3",
"roave/security-advisories": "dev-master",
"shlinkio/php-coding-standard": "~2.0.0",
"shlinkio/shlink-test-utils": "^1.1",
"symfony/dotenv": "^4.3",
"symfony/var-dumper": "^4.3",
"zendframework/zend-component-installer": "^2.1",
"zendframework/zend-expressive-tooling": "^1.2"
"shlinkio/shlink-test-utils": "^1.2",
"symfony/dotenv": "^5.0",
"symfony/var-dumper": "^5.0"
},
"autoload": {
"psr-4": {
@ -115,7 +112,7 @@
"@test:api"
],
"test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox",
"test:unit:ci": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/phpunit.junit.xml --testdox",
"test:unit:ci": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/junit.xml --testdox",
"test:db": [
"@test:db:sqlite",
"@test:db:mysql",
@ -132,10 +129,6 @@
"test:db:maria": "DB_DRIVER=maria composer test:db:sqlite",
"test:db:postgres": "DB_DRIVER=postgres composer test:db:sqlite",
"test:api": "bin/test/run-api-tests.sh",
"test:pretty": [
"@test",
"phpdbg -qrr vendor/bin/phpcov merge build --html build/html"
],
"test:unit:pretty": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-html build/coverage",
"infect": "infection --threads=4 --min-msi=75 --log-verbosity=default --only-covered",
"infect:ci": "infection --threads=4 --min-msi=75 --log-verbosity=default --only-covered --coverage=build",
@ -162,7 +155,6 @@
"test:db:maria": "<fg=blue;options=bold>Runs database test suites on a MariaDB database</>",
"test:db:postgres": "<fg=blue;options=bold>Runs database test suites on a PostgreSQL database</>",
"test:api": "<fg=blue;options=bold>Runs API test suites</>",
"test:pretty": "<fg=blue;options=bold>Runs all test suites and generates an HTML code coverage report</>",
"test:unit:pretty": "<fg=blue;options=bold>Runs unit test suites and generates an HTML code coverage report</>",
"infect": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing</>",
"infect:ci": "<fg=blue;options=bold>Checks unit tests quality applying mutation testing with existing reports and logs</>",

View file

@ -10,7 +10,7 @@ use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
// This class alias tricks the ConfigAbstractFactory to return Lock\Factory instances even with a different service name
$localLockFactory = 'Shlinkio\Shlink\LocalLockFactory';
class_alias(Lock\Factory::class, $localLockFactory);
class_alias(Lock\LockFactory::class, $localLockFactory);
return [
@ -22,7 +22,7 @@ return [
'factories' => [
Lock\Store\FlockStore::class => ConfigAbstractFactory::class,
Lock\Store\RedisStore::class => ConfigAbstractFactory::class,
Lock\Factory::class => ConfigAbstractFactory::class,
Lock\LockFactory::class => ConfigAbstractFactory::class,
$localLockFactory => ConfigAbstractFactory::class,
],
'aliases' => [
@ -36,7 +36,7 @@ return [
Lock\Store\RedisStore::class => [
RetryLockStoreDelegatorFactory::class,
],
Lock\Factory::class => [
Lock\LockFactory::class => [
LoggerAwareDelegatorFactory::class,
],
],
@ -45,7 +45,7 @@ return [
ConfigAbstractFactory::class => [
Lock\Store\FlockStore::class => ['config.locks.locks_dir'],
Lock\Store\RedisStore::class => [RedisFactory::SERVICE_NAME],
Lock\Factory::class => ['lock_store'],
Lock\LockFactory::class => ['lock_store'],
$localLockFactory => ['local_lock_store'],
],

View file

@ -4,64 +4,69 @@ declare(strict_types=1);
namespace Shlinkio\Shlink;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Formatter;
use Monolog\Handler;
use Monolog\Logger;
use Monolog\Processor;
use MonologFactory\DiContainerLoggerFactory;
use Psr\Log\LoggerInterface;
use const PHP_EOL;
$processors = [
'exception_with_new_line' => [
'name' => Common\Logger\Processor\ExceptionWithNewLineProcessor::class,
],
'psr3' => [
'name' => Processor\PsrLogMessageProcessor::class,
],
];
$formatter = [
'name' => Formatter\LineFormatter::class,
'params' => [
'format' => '[%datetime%] %channel%.%level_name% - %message%' . PHP_EOL,
'allow_inline_line_breaks' => true,
],
];
return [
'logger' => [
'formatters' => [
'dashed' => [
'format' => '[%datetime%] %channel%.%level_name% - %message%' . PHP_EOL,
'include_stacktraces' => true,
'Shlink' => [
'name' => 'Shlink',
'handlers' => [
'shlink_handler' => [
'name' => Handler\RotatingFileHandler::class,
'params' => [
'level' => Logger::INFO,
'filename' => 'data/log/shlink_log.log',
'max_files' => 30,
],
'formatter' => $formatter,
],
],
'processors' => $processors,
],
'handlers' => [
'shlink_rotating_handler' => [
'class' => RotatingFileHandler::class,
'level' => Logger::INFO,
'filename' => 'data/log/shlink_log.log',
'max_files' => 30,
'formatter' => 'dashed',
],
'access_handler' => [
'class' => StreamHandler::class,
'level' => Logger::INFO,
'stream' => 'php://stdout',
],
],
'processors' => [
'exception_with_new_line' => [
'class' => Common\Logger\Processor\ExceptionWithNewLineProcessor::class,
],
'psr3' => [
'class' => Processor\PsrLogMessageProcessor::class,
],
],
'loggers' => [
'Shlink' => [
'handlers' => ['shlink_rotating_handler'],
'processors' => ['exception_with_new_line', 'psr3'],
],
'Access' => [
'handlers' => ['access_handler'],
'processors' => ['exception_with_new_line', 'psr3'],
'Access' => [
'name' => 'Access',
'handlers' => [
'access_handler' => [
'name' => Handler\StreamHandler::class,
'params' => [
'level' => Logger::INFO,
'stream' => 'php://stdout',
],
'formatter' => $formatter,
],
],
'processors' => $processors,
],
],
'dependencies' => [
'factories' => [
'Logger_Shlink' => Common\Logger\LoggerFactory::class,
'Logger_Access' => Common\Logger\LoggerFactory::class,
'Logger_Shlink' => [DiContainerLoggerFactory::class, 'Shlink'],
'Logger_Access' => [DiContainerLoggerFactory::class, 'Access'],
],
'aliases' => [
'logger' => 'Logger_Shlink',

View file

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
use Monolog\Handler\StreamHandler;
@ -7,34 +8,28 @@ use Monolog\Logger;
$isSwoole = extension_loaded('swoole');
// For swoole, send logs to standard output
$logger = $isSwoole ? [
'handlers' => [
'shlink_rotating_handler' => [
'level' => Logger::EMERGENCY, // This basically disables regular file logs
],
'shlink_stdout_handler' => [
'class' => StreamHandler::class,
$handler = $isSwoole
? [
'name' => StreamHandler::class,
'params' => [
'level' => Logger::DEBUG,
'stream' => 'php://stdout',
'formatter' => 'dashed',
],
],
'loggers' => [
'Shlink' => [
'handlers' => ['shlink_stdout_handler'],
],
],
] : [
'handlers' => [
'shlink_rotating_handler' => [
]
: [
'params' => [
'level' => Logger::DEBUG,
],
],
];
];
return [
'logger' => $logger,
'logger' => [
'Shlink' => [
'handlers' => [
'shlink_handler' => $handler,
],
],
],
];

View file

@ -13,7 +13,7 @@ require 'vendor/autoload.php';
if (class_exists(Dotenv::class)) {
error_reporting(E_ALL);
ini_set('display_errors', '1');
$dotenv = new Dotenv();
$dotenv = new Dotenv(true);
$dotenv->load(__DIR__ . '/../.env');
}

View file

@ -130,21 +130,15 @@ return [
'not_found_redirects' => $helper->getNotFoundRedirectsConfig(),
'logger' => [
'handlers' => [
'shlink_rotating_handler' => [
'level' => Logger::EMERGENCY, // This basically disables regular file logs
],
'shlink_stdout_handler' => [
'class' => StreamHandler::class,
'level' => Logger::INFO,
'stream' => 'php://stdout',
'formatter' => 'dashed',
],
],
'loggers' => [
'Shlink' => [
'handlers' => ['shlink_stdout_handler'],
'Shlink' => [
'handlers' => [
'shlink_handler' => [
'name' => StreamHandler::class,
'params' => [
'level' => Logger::INFO,
'stream' => 'php://stdout',
],
],
],
],
],

View file

@ -15,7 +15,7 @@ use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use Shlinkio\Shlink\PreviewGenerator\Service\PreviewGenerator;
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use Symfony\Component\Console as SymfonyCli;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Process\PhpExecutableFinder;
use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory;
use Zend\ServiceManager\Factory\InvokableFactory;
@ -70,7 +70,7 @@ return [
Command\Visit\LocateVisitsCommand::class => [
Service\VisitService::class,
IpLocationResolverInterface::class,
Locker::class,
LockFactory::class,
GeolocationDbUpdater::class,
],
Command\Visit\UpdateDbCommand::class => [DbUpdater::class],
@ -85,14 +85,14 @@ return [
Command\Tag\DeleteTagsCommand::class => [Service\Tag\TagService::class],
Command\Db\CreateDatabaseCommand::class => [
Locker::class,
LockFactory::class,
SymfonyCli\Helper\ProcessHelper::class,
PhpExecutableFinder::class,
Connection::class,
NoDbNameConnectionFactory::SERVICE_NAME,
],
Command\Db\MigrateDatabaseCommand::class => [
Locker::class,
LockFactory::class,
SymfonyCli\Helper\ProcessHelper::class,
PhpExecutableFinder::class,
],

View file

@ -8,7 +8,7 @@ use Shlinkio\Shlink\CLI\Command\Util\AbstractLockedCommand;
use Shlinkio\Shlink\CLI\Command\Util\LockedCommandConfig;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Process\PhpExecutableFinder;
use function array_unshift;
@ -20,7 +20,7 @@ abstract class AbstractDatabaseCommand extends AbstractLockedCommand
/** @var string */
private $phpBinary;
public function __construct(Locker $locker, ProcessHelper $processHelper, PhpExecutableFinder $phpFinder)
public function __construct(LockFactory $locker, ProcessHelper $processHelper, PhpExecutableFinder $phpFinder)
{
parent::__construct($locker);
$this->processHelper = $processHelper;

View file

@ -10,7 +10,7 @@ use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Process\PhpExecutableFinder;
use function Functional\contains;
@ -27,7 +27,7 @@ class CreateDatabaseCommand extends AbstractDatabaseCommand
private $noDbNameConn;
public function __construct(
Locker $locker,
LockFactory $locker,
ProcessHelper $processHelper,
PhpExecutableFinder $phpFinder,
Connection $conn,

View file

@ -69,7 +69,7 @@ class GeneratePreviewCommand extends Command
} catch (PreviewGenerationException $e) {
$output->writeln(' <error>Error</error>');
if ($output->isVerbose()) {
$this->getApplication()->renderException($e, $output);
$this->getApplication()->renderThrowable($e, $output);
}
}
}

View file

@ -8,16 +8,16 @@ use Shlinkio\Shlink\CLI\Util\ExitCodes;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
use function sprintf;
abstract class AbstractLockedCommand extends Command
{
/** @var Locker */
/** @var LockFactory */
private $locker;
public function __construct(Locker $locker)
public function __construct(LockFactory $locker)
{
parent::__construct();
$this->locker = $locker;

View file

@ -22,7 +22,7 @@ use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
use Throwable;
use function sprintf;
@ -47,7 +47,7 @@ class LocateVisitsCommand extends AbstractLockedCommand
public function __construct(
VisitServiceInterface $visitService,
IpLocationResolverInterface $ipLocationResolver,
Locker $locker,
LockFactory $locker,
GeolocationDbUpdaterInterface $dbUpdater
) {
parent::__construct($locker);
@ -87,7 +87,7 @@ class LocateVisitsCommand extends AbstractLockedCommand
} catch (Throwable $e) {
$this->io->error($e->getMessage());
if ($e instanceof Exception && $this->io->isVerbose()) {
$this->getApplication()->renderException($e, $this->io);
$this->getApplication()->renderThrowable($e, $this->io);
}
return ExitCodes::EXIT_FAILURE;
@ -116,7 +116,7 @@ class LocateVisitsCommand extends AbstractLockedCommand
} catch (WrongIpException $e) {
$this->io->writeln(' [<fg=red>An error occurred while locating IP. Skipped</>]');
if ($this->io->isVerbose()) {
$this->getApplication()->renderException($e, $this->io);
$this->getApplication()->renderThrowable($e, $this->io);
}
throw IpCannotBeLocatedException::forError($e);

View file

@ -84,7 +84,7 @@ class UpdateDbCommand extends Command
$io->error($baseErrorMsg);
if ($io->isVerbose()) {
$this->getApplication()->renderException($e, $io);
$this->getApplication()->renderThrowable($e, $io);
}
return ExitCodes::EXIT_FAILURE;
}

View file

@ -9,7 +9,7 @@ use GeoIp2\Database\Reader;
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
use Shlinkio\Shlink\IpGeolocation\Exception\RuntimeException;
use Shlinkio\Shlink\IpGeolocation\GeoLite2\DbUpdaterInterface;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
{
@ -19,10 +19,10 @@ class GeolocationDbUpdater implements GeolocationDbUpdaterInterface
private $dbUpdater;
/** @var Reader */
private $geoLiteDbReader;
/** @var Locker */
/** @var LockFactory */
private $locker;
public function __construct(DbUpdaterInterface $dbUpdater, Reader $geoLiteDbReader, Locker $locker)
public function __construct(DbUpdaterInterface $dbUpdater, Reader $geoLiteDbReader, LockFactory $locker)
{
$this->dbUpdater = $dbUpdater;
$this->geoLiteDbReader = $geoLiteDbReader;

View file

@ -15,7 +15,7 @@ use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Process\PhpExecutableFinder;
@ -36,7 +36,7 @@ class CreateDatabaseCommandTest extends TestCase
public function setUp(): void
{
$locker = $this->prophesize(Locker::class);
$locker = $this->prophesize(LockFactory::class);
$lock = $this->prophesize(LockInterface::class);
$lock->acquire(Argument::any())->willReturn(true);
$lock->release()->will(function () {

View file

@ -12,7 +12,7 @@ use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Lock\Factory as Locker;
use Symfony\Component\Lock\LockFactory;
use Symfony\Component\Lock\LockInterface;
use Symfony\Component\Process\PhpExecutableFinder;
@ -25,7 +25,7 @@ class MigrateDatabaseCommandTest extends TestCase
public function setUp(): void
{
$locker = $this->prophesize(Locker::class);
$locker = $this->prophesize(LockFactory::class);
$lock = $this->prophesize(LockInterface::class);
$lock->acquire(Argument::any())->willReturn(true);
$lock->release()->will(function () {

View file

@ -48,7 +48,7 @@ class LocateVisitsCommandTest extends TestCase
$this->ipResolver = $this->prophesize(IpLocationResolverInterface::class);
$this->dbUpdater = $this->prophesize(GeolocationDbUpdaterInterface::class);
$this->locker = $this->prophesize(Lock\Factory::class);
$this->locker = $this->prophesize(Lock\LockFactory::class);
$this->lock = $this->prophesize(Lock\LockInterface::class);
$this->lock->acquire(false)->willReturn(true);
$this->lock->release()->will(function () {

View file

@ -38,7 +38,7 @@ class GeolocationDbUpdaterTest extends TestCase
$this->dbUpdater = $this->prophesize(DbUpdaterInterface::class);
$this->geoLiteDbReader = $this->prophesize(Reader::class);
$this->locker = $this->prophesize(Lock\Factory::class);
$this->locker = $this->prophesize(Lock\LockFactory::class);
$this->lock = $this->prophesize(Lock\LockInterface::class);
$this->lock->acquire(true)->willReturn(true);
$this->lock->release()->will(function () {