-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPENEUROPA-1126: Use logger factory as a service. #12
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
services: | ||
oe_webtools_analytics.event_subscriber: | ||
class: Drupal\oe_webtools_analytics\EventSubscriber\AnalyticsEventSubscriber | ||
arguments: ['@config.factory', '@request_stack'] | ||
arguments: ['@config.factory', '@request_stack', '@logger.factory'] | ||
tags: | ||
- { name: event_subscriber } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
namespace Drupal\oe_webtools_analytics\EventSubscriber; | ||
|
||
use Drupal\Core\Config\ImmutableConfig; | ||
use Drupal\Core\Logger\LoggerChannelFactoryInterface; | ||
use Drupal\oe_webtools_analytics\AnalyticsEventInterface; | ||
use Drupal\Core\Url; | ||
use Drupal\Core\Config\ConfigFactoryInterface; | ||
|
@@ -37,6 +38,13 @@ class AnalyticsEventSubscriber implements EventSubscriberInterface { | |
*/ | ||
private $requestStack; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @var \Drupal\Core\Logger\ | ||
*/ | ||
private $loggerFactory; | ||
|
||
/** | ||
* The search parameter object. | ||
* | ||
|
@@ -51,11 +59,14 @@ class AnalyticsEventSubscriber implements EventSubscriberInterface { | |
* The configuration object. | ||
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack | ||
* The request on the stack. | ||
* @param \LoggerChannelFactoryInterface $loggerFactory | ||
* The logger channel factory. | ||
*/ | ||
public function __construct(ConfigFactoryInterface $configFactory, RequestStack $requestStack) { | ||
public function __construct(ConfigFactoryInterface $configFactory, RequestStack $requestStack, LoggerChannelFactoryInterface $loggerFactory) { | ||
// Get id from settings.php! | ||
$this->config = $configFactory->get(AnalyticsEventInterface::CONFIG_NAME); | ||
$this->requestStack = $requestStack; | ||
$this->loggerFactory = $loggerFactory; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not set logger factory in the class, but directly the channel.
And then you have |
||
} | ||
|
||
/** | ||
|
@@ -85,13 +96,11 @@ public function getConfig(): ImmutableConfig { | |
* Response event. | ||
*/ | ||
public function onSetSiteDefaults(AnalyticsEventInterface $event) { | ||
$factory = \Drupal::service('logger.factory'); | ||
|
||
// SiteID must exist and be an integer. | ||
$site_id = $this->getConfig()->get(AnalyticsEventInterface::SITE_ID); | ||
if (!is_numeric($site_id)) { | ||
$factory | ||
->get('default') | ||
$this->loggerFactory | ||
->get('oe_webtools') | ||
->debug('The setting "' . AnalyticsEventInterface::SITE_ID . '" is missing from settings file.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make this a |
||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect namespace here in the docblock.