Skip to content
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

Merged
merged 3 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ services:
# o: addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
# device: ":${PWD}/"

#### End Mac users.
#### End Mac users.
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
Expand Up @@ -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;
Expand Down Expand Up @@ -37,6 +38,13 @@ class AnalyticsEventSubscriber implements EventSubscriberInterface {
*/
private $requestStack;

/**
* {@inheritdoc}
*
* @var \Drupal\Core\LoggerChannelInterface
*/
private $logger;

/**
* The search parameter object.
*
Expand All @@ -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->logger = $loggerFactory->get('oe_webtools');
}

/**
Expand Down Expand Up @@ -85,14 +96,10 @@ 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')
->debug('The setting "' . AnalyticsEventInterface::SITE_ID . '" is missing from settings file.');
$this->logger->warning('The setting "' . AnalyticsEventInterface::SITE_ID . '" is missing from settings file.');
return;
}

Expand Down