-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from City-of-Helsinki/UHF-9986
UHF-9986: Monolog dependency
- Loading branch information
Showing
12 changed files
with
84 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
logger: true | ||
disable_user_password: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
# Logging | ||
|
||
Errors caught by Drupal will be logged to `temporary://drupal.log` file as JSON, which will be piped to container stdout by [15-syslog.sh](https://github.com/City-of-Helsinki/drupal-docker-images/blob/main/openshift/drupal/files/entrypoints/15-syslog.sh) docker entrypoint. | ||
Errors caught by Drupal will be logged to `php://stdout` by `drupal/monolog` module. | ||
|
||
JSON parsing needs to be enabled manually in order for this to work. See https://helsinkisolutionoffice.atlassian.net/wiki/spaces/HELFI/pages/7854817294/Logging+Structured+logs#Configuration-using-openshift-console. | ||
|
||
## How to disable logging | ||
## Usage | ||
|
||
Call: | ||
```php | ||
$service = \Drupal::service(\Drupal\helfi_api_base\Features\FeatureManager::class); | ||
$service->disableFeature(\Drupal\helfi_api_base\Features\FeatureManager::LOGGER); | ||
``` | ||
|
||
and export the changed configuration. | ||
Enable `monolog` module: `drush en monolog`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\helfi_api_base; | ||
|
||
use Drupal\Core\DependencyInjection\ContainerBuilder; | ||
use Drupal\Core\DependencyInjection\ServiceProviderBase; | ||
use Drupal\monolog\Logger\Formatter\ConditionalFormatter; | ||
use Drupal\monolog\Logger\Handler\ConditionalHandler; | ||
use Drupal\monolog\Logger\Handler\DrupalHandler; | ||
use Drush\Log\DrushLog; | ||
use Monolog\Handler\StreamHandler; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* A service provider for 'helfi_api_base' module. | ||
*/ | ||
final class HelfiApiBaseServiceProvider extends ServiceProviderBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function register(ContainerBuilder $container) : void { | ||
// We cannot use the module handler as the container is not yet compiled. | ||
// @see \Drupal\Core\DrupalKernel::compileContainer() | ||
$modules = $container->getParameter('container.modules'); | ||
|
||
if (isset($modules['monolog'])) { | ||
$container->setParameter('monolog.channel_handlers', [ | ||
'default' => [ | ||
'handlers' => [ | ||
[ | ||
'name' => 'default_conditional_handler', | ||
'formatter' => 'drush_or_json', | ||
], | ||
], | ||
], | ||
]); | ||
|
||
if (!$container->has('logger.drupaltodrush')) { | ||
$container->register('logger.drupaltodrush', DrushLog::class) | ||
->addArgument(new Reference('logger.log_message_parser')) | ||
->addTag('logger'); | ||
} | ||
if (!$container->has('monolog.handler.drupal.drupaltodrush')) { | ||
$container->register('monolog.handler.drupal.drupaltodrush', DrupalHandler::class) | ||
->addArgument(new Reference('logger.drupaltodrush')) | ||
->setShared(FALSE); | ||
} | ||
$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')); | ||
$container->register('monolog.handler.website', StreamHandler::class) | ||
->addArgument('php://stdout'); | ||
$container->register('monolog.formatter.drush_or_json', ConditionalFormatter::class) | ||
->addArgument(new Reference('monolog.formatter.drush')) | ||
->addArgument(new Reference('monolog.formatter.json')) | ||
->addArgument(new Reference('monolog.condition_resolver.cli')) | ||
->setShared(FALSE); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.