Skip to content

Commit

Permalink
UHF-10751: Add log level to monolog
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Oct 8, 2024
1 parent 7a37870 commit ce7ff81
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions helfi_api_base.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ parameters:
helfi_api_base.disable_password_users:
- helfi-admin
- 1
# Supported values:
# https://github.com/Seldaek/monolog/blob/main/doc/01-usage.md#log-levels.
helfi_api_base.log_level: 200
services:
_defaults:
autowire: true
Expand Down
10 changes: 9 additions & 1 deletion src/HelfiApiBaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Drupal\monolog\Logger\Handler\DrupalHandler;
use Drush\Log\DrushLog;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use Symfony\Component\DependencyInjection\Reference;

/**
Expand All @@ -27,6 +28,12 @@ public function register(ContainerBuilder $container) : void {
$modules = $container->getParameter('container.modules');

if (isset($modules['monolog'])) {
$logLevel = Level::Info->value;

if ($container->hasParameter('helfi_api_base.log_level')) {
$logLevel = $container->getParameter('helfi_api_base.log_level');
}

$container->setParameter('monolog.channel_handlers', [
'default' => [
'handlers' => [
Expand All @@ -51,7 +58,8 @@ public function register(ContainerBuilder $container) : void {
$container->register('monolog.handler.default_conditional_handler', ConditionalHandler::class)
->addArgument(new Reference('monolog.handler.drupal.drupaltodrush'))
->addArgument(new Reference('monolog.handler.website'))
->addArgument(new Reference('monolog.condition_resolver.cli'));
->addArgument(new Reference('monolog.condition_resolver.cli'))
->addArgument($logLevel);
$container->register('monolog.handler.website', StreamHandler::class)
->addArgument('php://stdout');
$container->register('monolog.formatter.drush_or_json', ConditionalFormatter::class)
Expand Down

0 comments on commit ce7ff81

Please sign in to comment.