Skip to content

Commit

Permalink
VACMS-19175: new monolog current user processor (#19338)
Browse files Browse the repository at this point in the history
  • Loading branch information
edmund-dunn authored Sep 27, 2024
1 parent cc54684 commit a7e9d9d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Drupal\va_gov_user\Logger\Processor;

use Drupal\Core\Session\AccountProxyInterface;
use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;

/**
* Processor that adds user information to the log records.
*/
class VaGovUserCurrentUserProcessor implements ProcessorInterface {

/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $accountProxy;

/**
* Constructs a Default object.
*
* @param \Drupal\Core\Session\AccountProxyInterface $account_proxy
* The current user.
*/
public function __construct(AccountProxyInterface $account_proxy) {
$this->accountProxy = $account_proxy;
}

/**
* {@inheritdoc}
*/
public function __invoke(LogRecord $record): LogRecord {
$record->extra = \array_merge(
$record->extra,
[
'uid' => $this->accountProxy->id(),
'user' => $this->accountProxy->id(),
],
);

return $record;
}

}
3 changes: 3 additions & 0 deletions docroot/modules/custom/va_gov_user/va_gov_user.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ services:
va_gov_user.user_perms:
class: Drupal\va_gov_user\Service\UserPermsService
arguments: ['@current_user', '@entity_type.manager', '@database']
monolog.processor.va_gov_current_user:
class: Drupal\va_gov_user\Logger\Processor\VaGovUserCurrentUserProcessor
arguments: ['@current_user']
1 change: 1 addition & 0 deletions docroot/sites/default/services/services.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:
- 'drupal.syslog'
- 'error_log'
monolog.processors:
- 'va_gov_current_user'
- 'filter_backtrace'
- 'ip'
- 'message_placeholder'
Expand Down
1 change: 1 addition & 0 deletions docroot/sites/default/services/services.monolog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parameters:
- 'drupal.dblog'
- 'error_log'
monolog.processors:
- 'va_gov_current_user'
- 'filter_backtrace'
- 'ip'
- 'message_placeholder'
Expand Down
1 change: 1 addition & 0 deletions docroot/sites/default/services/services.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:
- 'drupal.syslog'
- 'error_log'
monolog.processors:
- 'va_gov_current_user'
- 'filter_backtrace'
- 'ip'
- 'message_placeholder'
Expand Down
1 change: 1 addition & 0 deletions docroot/sites/default/services/services.staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ parameters:
- 'drupal.syslog'
- 'error_log'
monolog.processors:
- 'va_gov_current_user'
- 'filter_backtrace'
- 'ip'
- 'message_placeholder'
Expand Down

0 comments on commit a7e9d9d

Please sign in to comment.