diff --git a/bin/cli b/bin/cli
index ea8cb5c3..3284eea8 100755
--- a/bin/cli
+++ b/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();
diff --git a/config/autoload/logger.global.php b/config/autoload/logger.global.php
index 363e9210..6782bfbe 100644
--- a/config/autoload/logger.global.php
+++ b/config/autoload/logger.global.php
@@ -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'],
],
],
diff --git a/config/autoload/logger.local.php.dist b/config/autoload/logger.local.php.dist
index 951a3af0..08628b6a 100644
--- a/config/autoload/logger.local.php.dist
+++ b/config/autoload/logger.local.php.dist
@@ -1,11 +1,13 @@
[
'handlers' => [
- 'rotating_file_handler' => [
+ 'shlink_log_handler' => [
'level' => Logger::DEBUG,
],
],
diff --git a/module/Common/src/Exec/ExecutionContext.php b/module/Common/src/Exec/ExecutionContext.php
new file mode 100644
index 00000000..214d7571
--- /dev/null
+++ b/module/Common/src/Exec/ExecutionContext.php
@@ -0,0 +1,18 @@
+config
public/index.php
config/params/*
+ public/index.php
diff --git a/public/index.php b/public/index.php
index fa5d778c..f9469830 100644
--- a/public/index.php
+++ b/public/index.php
@@ -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();