mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-13 09:31:56 -06:00
Standardize logger for all Shlink execution contexts
This commit is contained in:
parent
28d93ea5e0
commit
a797b74a70
@ -45,7 +45,7 @@
|
|||||||
"php-middleware/request-id": "^4.1",
|
"php-middleware/request-id": "^4.1",
|
||||||
"pugx/shortid-php": "^1.1",
|
"pugx/shortid-php": "^1.1",
|
||||||
"ramsey/uuid": "^4.7",
|
"ramsey/uuid": "^4.7",
|
||||||
"shlinkio/shlink-common": "dev-main#29dd933 as 5.5",
|
"shlinkio/shlink-common": "dev-main#88a34f1 as 5.5",
|
||||||
"shlinkio/shlink-config": "^2.4",
|
"shlinkio/shlink-config": "^2.4",
|
||||||
"shlinkio/shlink-event-dispatcher": "dev-main#8c677ae as 3.0",
|
"shlinkio/shlink-event-dispatcher": "dev-main#8c677ae as 3.0",
|
||||||
"shlinkio/shlink-importer": "dev-main#6b63b12 as 5.1",
|
"shlinkio/shlink-importer": "dev-main#6b63b12 as 5.1",
|
||||||
|
@ -4,51 +4,63 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Shlinkio\Shlink;
|
namespace Shlinkio\Shlink;
|
||||||
|
|
||||||
|
use Laminas\ServiceManager\Factory\InvokableFactory;
|
||||||
use Monolog\Level;
|
use Monolog\Level;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use PhpMiddleware\RequestId;
|
use PhpMiddleware\RequestId;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Shlinkio\Shlink\Common\Logger\LoggerFactory;
|
use Shlinkio\Shlink\Common\Logger\LoggerFactory;
|
||||||
use Shlinkio\Shlink\Common\Logger\LoggerType;
|
use Shlinkio\Shlink\Common\Logger\LoggerType;
|
||||||
|
use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware;
|
||||||
|
|
||||||
$common = [
|
use function Shlinkio\Shlink\Config\runningInRoadRunner;
|
||||||
'level' => Level::Info->value,
|
|
||||||
'processors' => [RequestId\MonologProcessor::class],
|
|
||||||
'line_format' => '[%datetime%] [%extra.request_id%] %channel%.%level_name% - %message%',
|
|
||||||
];
|
|
||||||
|
|
||||||
return [
|
return (static function (): array {
|
||||||
|
$common = [
|
||||||
|
'level' => Level::Info->value,
|
||||||
|
'processors' => [RequestId\MonologProcessor::class],
|
||||||
|
'line_format' => '[%datetime%] [%extra.request_id%] %channel%.%level_name% - %message%',
|
||||||
|
];
|
||||||
|
|
||||||
'logger' => [
|
return [
|
||||||
'Shlink' => [
|
|
||||||
'type' => LoggerType::FILE->value,
|
|
||||||
...$common,
|
|
||||||
],
|
|
||||||
'Access' => [
|
|
||||||
'type' => LoggerType::STREAM->value,
|
|
||||||
...$common,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
|
|
||||||
'dependencies' => [
|
'logger' => [
|
||||||
'factories' => [
|
'Shlink' => [
|
||||||
'Logger_Shlink' => [LoggerFactory::class, 'Shlink'],
|
'type' => LoggerType::FILE->value,
|
||||||
'Logger_Access' => [LoggerFactory::class, 'Access'],
|
...$common,
|
||||||
],
|
],
|
||||||
'aliases' => [
|
'Access' => [
|
||||||
'logger' => 'Logger_Shlink',
|
'type' => LoggerType::STREAM->value,
|
||||||
Logger::class => 'Logger_Shlink',
|
'destination' => 'php://stderr',
|
||||||
LoggerInterface::class => 'Logger_Shlink',
|
'add_new_line' => ! runningInRoadRunner(),
|
||||||
],
|
...$common,
|
||||||
],
|
|
||||||
|
|
||||||
'mezzio-swoole' => [
|
|
||||||
'swoole-http-server' => [
|
|
||||||
'logger' => [
|
|
||||||
'logger-name' => 'Logger_Access',
|
|
||||||
'format' => '%u "%r" %>s %B',
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
],
|
|
||||||
|
|
||||||
];
|
'dependencies' => [
|
||||||
|
'factories' => [
|
||||||
|
'Logger_Shlink' => [LoggerFactory::class, 'Shlink'],
|
||||||
|
'Logger_Access' => [LoggerFactory::class, 'Access'],
|
||||||
|
NullLogger::class => InvokableFactory::class,
|
||||||
|
],
|
||||||
|
'aliases' => [
|
||||||
|
'logger' => 'Logger_Shlink',
|
||||||
|
Logger::class => 'Logger_Shlink',
|
||||||
|
LoggerInterface::class => 'Logger_Shlink',
|
||||||
|
AccessLogMiddleware::LOGGER_SERVICE_NAME => 'Logger_Access',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
'mezzio-swoole' => [
|
||||||
|
'swoole-http-server' => [
|
||||||
|
'logger' => [
|
||||||
|
// Let's disable mezio-swoole access logging, so that we can provide our own implementation,
|
||||||
|
// consistent for roadrunner and openswoole
|
||||||
|
'logger-name' => NullLogger::class,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
})();
|
||||||
|
@ -5,16 +5,12 @@ declare(strict_types=1);
|
|||||||
use Monolog\Level;
|
use Monolog\Level;
|
||||||
use Shlinkio\Shlink\Common\Logger\LoggerType;
|
use Shlinkio\Shlink\Common\Logger\LoggerType;
|
||||||
|
|
||||||
use function Shlinkio\Shlink\Config\runningInOpenswoole;
|
|
||||||
|
|
||||||
$logToStream = runningInOpenswoole();
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'logger' => [
|
'logger' => [
|
||||||
'Shlink' => [
|
'Shlink' => [
|
||||||
// For openswoole, send logs as stream
|
'type' => LoggerType::STREAM->value,
|
||||||
'type' => $logToStream ? LoggerType::STREAM->value : LoggerType::FILE->value,
|
'destination' => 'php://stderr',
|
||||||
'level' => Level::Debug->value,
|
'level' => Level::Debug->value,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -9,6 +9,7 @@ use Mezzio\ProblemDetails;
|
|||||||
use Mezzio\Router;
|
use Mezzio\Router;
|
||||||
use PhpMiddleware\RequestId\RequestIdMiddleware;
|
use PhpMiddleware\RequestId\RequestIdMiddleware;
|
||||||
use RKA\Middleware\IpAddress;
|
use RKA\Middleware\IpAddress;
|
||||||
|
use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware;
|
||||||
use Shlinkio\Shlink\Common\Middleware\ContentLengthMiddleware;
|
use Shlinkio\Shlink\Common\Middleware\ContentLengthMiddleware;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@ -16,6 +17,7 @@ return [
|
|||||||
'middleware_pipeline' => [
|
'middleware_pipeline' => [
|
||||||
'error-handler' => [
|
'error-handler' => [
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
|
AccessLogMiddleware::class,
|
||||||
ContentLengthMiddleware::class,
|
ContentLengthMiddleware::class,
|
||||||
RequestIdMiddleware::class,
|
RequestIdMiddleware::class,
|
||||||
ErrorHandler::class,
|
ErrorHandler::class,
|
||||||
|
@ -31,7 +31,7 @@ logs:
|
|||||||
mode: development
|
mode: development
|
||||||
channels:
|
channels:
|
||||||
http:
|
http:
|
||||||
level: debug
|
mode: 'off' # Disable logging as Shlink handles it internally
|
||||||
server:
|
server:
|
||||||
level: debug
|
level: debug
|
||||||
metrics:
|
metrics:
|
||||||
|
@ -31,6 +31,6 @@ logs:
|
|||||||
mode: production
|
mode: production
|
||||||
channels:
|
channels:
|
||||||
http:
|
http:
|
||||||
level: info # Log all http requests, set to info to disable
|
mode: 'off' # Disable logging as Shlink handles it internally
|
||||||
server:
|
server:
|
||||||
level: debug # Everything written to worker stderr is logged
|
level: debug # Everything written to worker stderr is logged
|
||||||
|
@ -121,6 +121,7 @@ $buildTestLoggerConfig = static fn (string $filename) => [
|
|||||||
'level' => Level::Debug->value,
|
'level' => Level::Debug->value,
|
||||||
'type' => LoggerType::STREAM->value,
|
'type' => LoggerType::STREAM->value,
|
||||||
'destination' => sprintf('data/log/api-tests/%s', $filename),
|
'destination' => sprintf('data/log/api-tests/%s', $filename),
|
||||||
|
'add_new_line' => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -6,14 +6,12 @@ namespace Shlinkio\Shlink;
|
|||||||
|
|
||||||
use Shlinkio\Shlink\Common\Logger\LoggerType;
|
use Shlinkio\Shlink\Common\Logger\LoggerType;
|
||||||
|
|
||||||
use function Shlinkio\Shlink\Config\runningInRoadRunner;
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'logger' => [
|
'logger' => [
|
||||||
'Shlink' => [
|
'Shlink' => [
|
||||||
'type' => LoggerType::STREAM->value,
|
'type' => LoggerType::STREAM->value,
|
||||||
'destination' => runningInRoadRunner() ? 'php://stderr' : 'php://stdout',
|
'destination' => 'php://stderr',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user