mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-27 20:11:34 +03:00
Replaced monolog-cascade by MonologFactory
This commit is contained in:
parent
e558bb17cb
commit
cf3d763731
7 changed files with 75 additions and 83 deletions
|
@ -4,67 +4,69 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shlinkio\Shlink;
|
namespace Shlinkio\Shlink;
|
||||||
|
|
||||||
use Monolog\Handler\RotatingFileHandler;
|
use Monolog\Formatter;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Monolog\Processor;
|
use Monolog\Processor;
|
||||||
|
use MonologFactory\DiContainerLoggerFactory;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
use const PHP_EOL;
|
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,
|
||||||
|
'include_stacktraces' => true,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'logger' => [
|
'logger' => [
|
||||||
'formatters' => [
|
'Shlink' => [
|
||||||
'dashed' => [
|
'name' => 'Shlink',
|
||||||
'format' => '[%datetime%] %channel%.%level_name% - %message%' . PHP_EOL,
|
'handlers' => [
|
||||||
'include_stacktraces' => true,
|
'shlink_handler' => [
|
||||||
],
|
'name' => Handler\RotatingFileHandler::class,
|
||||||
],
|
'params' => [
|
||||||
|
'level' => Logger::INFO,
|
||||||
'handlers' => [
|
'filename' => 'data/log/shlink_log.log',
|
||||||
'shlink_rotating_handler' => [
|
'max_files' => 30,
|
||||||
'class' => RotatingFileHandler::class,
|
],
|
||||||
'level' => Logger::INFO,
|
'formatter' => $formatter,
|
||||||
'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' => [
|
|
||||||
// Using a key allows for this to be overwritten
|
|
||||||
'shlink_handler' => 'shlink_rotating_handler',
|
|
||||||
],
|
],
|
||||||
'processors' => ['exception_with_new_line', 'psr3'],
|
|
||||||
],
|
],
|
||||||
'Access' => [
|
'processors' => $processors,
|
||||||
'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' => [
|
'dependencies' => [
|
||||||
'factories' => [
|
'factories' => [
|
||||||
'Logger_Shlink' => Common\Logger\LoggerFactory::class,
|
'Logger_Shlink' => [DiContainerLoggerFactory::class, 'Shlink'],
|
||||||
'Logger_Access' => Common\Logger\LoggerFactory::class,
|
'Logger_Access' => [DiContainerLoggerFactory::class, 'Access'],
|
||||||
],
|
],
|
||||||
'aliases' => [
|
'aliases' => [
|
||||||
'logger' => 'Logger_Shlink',
|
'logger' => 'Logger_Shlink',
|
||||||
|
|
|
@ -8,33 +8,28 @@ use Monolog\Logger;
|
||||||
$isSwoole = extension_loaded('swoole');
|
$isSwoole = extension_loaded('swoole');
|
||||||
|
|
||||||
// For swoole, send logs to standard output
|
// For swoole, send logs to standard output
|
||||||
$logger = $isSwoole ? [
|
$handler = $isSwoole
|
||||||
'handlers' => [
|
? [
|
||||||
'shlink_stdout_handler' => [
|
'name' => StreamHandler::class,
|
||||||
'class' => StreamHandler::class,
|
'params' => [
|
||||||
'level' => Logger::DEBUG,
|
'level' => Logger::DEBUG,
|
||||||
'stream' => 'php://stdout',
|
'stream' => 'php://stdout',
|
||||||
'formatter' => 'dashed',
|
|
||||||
],
|
],
|
||||||
],
|
]
|
||||||
|
: [
|
||||||
'loggers' => [
|
'params' => [
|
||||||
'Shlink' => [
|
|
||||||
'handlers' => [
|
|
||||||
'shlink_handler' => 'shlink_stdout_handler',
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
] : [
|
|
||||||
'handlers' => [
|
|
||||||
'shlink_rotating_handler' => [
|
|
||||||
'level' => Logger::DEBUG,
|
'level' => Logger::DEBUG,
|
||||||
],
|
],
|
||||||
],
|
];
|
||||||
];
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'logger' => $logger,
|
'logger' => [
|
||||||
|
'Shlink' => [
|
||||||
|
'handlers' => [
|
||||||
|
'shlink_handler' => $handler,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -130,19 +130,14 @@ return [
|
||||||
'not_found_redirects' => $helper->getNotFoundRedirectsConfig(),
|
'not_found_redirects' => $helper->getNotFoundRedirectsConfig(),
|
||||||
|
|
||||||
'logger' => [
|
'logger' => [
|
||||||
'handlers' => [
|
'Shlink' => [
|
||||||
'shlink_stdout_handler' => [
|
'handlers' => [
|
||||||
'class' => StreamHandler::class,
|
'shlink_handler' => [
|
||||||
'level' => Logger::INFO,
|
'name' => StreamHandler::class,
|
||||||
'stream' => 'php://stdout',
|
'params' => [
|
||||||
'formatter' => 'dashed',
|
'level' => Logger::INFO,
|
||||||
],
|
'stream' => 'php://stdout',
|
||||||
],
|
],
|
||||||
|
|
||||||
'loggers' => [
|
|
||||||
'Shlink' => [
|
|
||||||
'handlers' => [
|
|
||||||
'shlink_handler' => 'shlink_stdout_handler',
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
|
@ -15,7 +15,7 @@ use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Helper\ProcessHelper;
|
use Symfony\Component\Console\Helper\ProcessHelper;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
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\Lock\LockInterface;
|
||||||
use Symfony\Component\Process\PhpExecutableFinder;
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class CreateDatabaseCommandTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$locker = $this->prophesize(Locker::class);
|
$locker = $this->prophesize(LockFactory::class);
|
||||||
$lock = $this->prophesize(LockInterface::class);
|
$lock = $this->prophesize(LockInterface::class);
|
||||||
$lock->acquire(Argument::any())->willReturn(true);
|
$lock->acquire(Argument::any())->willReturn(true);
|
||||||
$lock->release()->will(function () {
|
$lock->release()->will(function () {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Helper\ProcessHelper;
|
use Symfony\Component\Console\Helper\ProcessHelper;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
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\Lock\LockInterface;
|
||||||
use Symfony\Component\Process\PhpExecutableFinder;
|
use Symfony\Component\Process\PhpExecutableFinder;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class MigrateDatabaseCommandTest extends TestCase
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$locker = $this->prophesize(Locker::class);
|
$locker = $this->prophesize(LockFactory::class);
|
||||||
$lock = $this->prophesize(LockInterface::class);
|
$lock = $this->prophesize(LockInterface::class);
|
||||||
$lock->acquire(Argument::any())->willReturn(true);
|
$lock->acquire(Argument::any())->willReturn(true);
|
||||||
$lock->release()->will(function () {
|
$lock->release()->will(function () {
|
||||||
|
|
|
@ -48,7 +48,7 @@ class LocateVisitsCommandTest extends TestCase
|
||||||
$this->ipResolver = $this->prophesize(IpLocationResolverInterface::class);
|
$this->ipResolver = $this->prophesize(IpLocationResolverInterface::class);
|
||||||
$this->dbUpdater = $this->prophesize(GeolocationDbUpdaterInterface::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 = $this->prophesize(Lock\LockInterface::class);
|
||||||
$this->lock->acquire(false)->willReturn(true);
|
$this->lock->acquire(false)->willReturn(true);
|
||||||
$this->lock->release()->will(function () {
|
$this->lock->release()->will(function () {
|
||||||
|
|
|
@ -38,7 +38,7 @@ class GeolocationDbUpdaterTest extends TestCase
|
||||||
$this->dbUpdater = $this->prophesize(DbUpdaterInterface::class);
|
$this->dbUpdater = $this->prophesize(DbUpdaterInterface::class);
|
||||||
$this->geoLiteDbReader = $this->prophesize(Reader::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 = $this->prophesize(Lock\LockInterface::class);
|
||||||
$this->lock->acquire(true)->willReturn(true);
|
$this->lock->acquire(true)->willReturn(true);
|
||||||
$this->lock->release()->will(function () {
|
$this->lock->release()->will(function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue