mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 00:47:25 -06:00
Updated config so that shlink logger dynamically uses standard output when running with swoole
This commit is contained in:
parent
16590b2dbb
commit
2fc2ad98aa
3
bin/cli
3
bin/cli
@ -3,8 +3,11 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Shlinkio\Shlink\Common\Exec\ExecutionContext;
|
||||
use Symfony\Component\Console\Application as CliApp;
|
||||
|
||||
/** @var ContainerInterface $container */
|
||||
$container = include __DIR__ . '/../config/container.php';
|
||||
|
||||
putenv(sprintf('CURRENT_SHLINK_CONTEXT=%s', ExecutionContext::CLI));
|
||||
$container->get(CliApp::class)->run();
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace Shlinkio\Shlink;
|
||||
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use Monolog\Processor;
|
||||
use const PHP_EOL;
|
||||
@ -19,12 +20,17 @@ return [
|
||||
],
|
||||
|
||||
'handlers' => [
|
||||
'rotating_file_handler' => [
|
||||
'shlink_log_handler' => Common\Exec\ExecutionContext::currentContextIsSwoole() ? [
|
||||
'class' => StreamHandler::class,
|
||||
'level' => Logger::INFO,
|
||||
'stream' => 'php://stdout',
|
||||
'formatter' => 'dashed',
|
||||
] : [
|
||||
'class' => RotatingFileHandler::class,
|
||||
'level' => Logger::INFO,
|
||||
'filename' => 'data/log/shlink_log.log',
|
||||
'max_files' => 30,
|
||||
'formatter' => 'dashed',
|
||||
'max_files' => 30,
|
||||
],
|
||||
],
|
||||
|
||||
@ -39,7 +45,7 @@ return [
|
||||
|
||||
'loggers' => [
|
||||
'Shlink' => [
|
||||
'handlers' => ['rotating_file_handler'],
|
||||
'handlers' => ['shlink_log_handler'],
|
||||
'processors' => ['exception_with_new_line', 'psr3'],
|
||||
],
|
||||
],
|
||||
|
@ -1,11 +1,13 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
return [
|
||||
|
||||
'logger' => [
|
||||
'handlers' => [
|
||||
'rotating_file_handler' => [
|
||||
'shlink_log_handler' => [
|
||||
'level' => Logger::DEBUG,
|
||||
],
|
||||
],
|
||||
|
18
module/Common/src/Exec/ExecutionContext.php
Normal file
18
module/Common/src/Exec/ExecutionContext.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Exec;
|
||||
|
||||
use const PHP_SAPI;
|
||||
use function Shlinkio\Shlink\Common\env;
|
||||
|
||||
abstract class ExecutionContext
|
||||
{
|
||||
public const WEB = 'shlink_web';
|
||||
public const CLI = 'shlink_cli';
|
||||
|
||||
public static function currentContextIsSwoole(): bool
|
||||
{
|
||||
return PHP_SAPI === 'cli' && env('CURRENT_SHLINK_CONTEXT', self::WEB) === self::WEB;
|
||||
}
|
||||
}
|
@ -56,4 +56,5 @@
|
||||
<file>config</file>
|
||||
<file>public/index.php</file>
|
||||
<exclude-pattern>config/params/*</exclude-pattern>
|
||||
<exclude-pattern>public/index.php</exclude-pattern>
|
||||
</ruleset>
|
||||
|
@ -2,8 +2,11 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Shlinkio\Shlink\Common\Exec\ExecutionContext;
|
||||
use Zend\Expressive\Application;
|
||||
|
||||
/** @var ContainerInterface $container */
|
||||
$container = include __DIR__ . '/../config/container.php';
|
||||
|
||||
putenv(sprintf('CURRENT_SHLINK_CONTEXT=%s', ExecutionContext::WEB));
|
||||
$container->get(Application::class)->run();
|
||||
|
Loading…
Reference in New Issue
Block a user