You are here

class DBLogFilter in DBLog Filter 8.2

Same name and namespace in other branches
  1. 8 src/Logger/DBLogFilter.php \Drupal\dblog_filter\Logger\DBLogFilter

DBLogFilter Class.

Hierarchy

Expanded class hierarchy of DBLogFilter

File

src/Logger/DBLogFilter.php, line 14

Namespace

Drupal\dblog_filter\Logger
View source
class DBLogFilter extends DbLog {
  use RfcLoggerTrait;

  /**
   * Constructs a DbLogFilter object.
   *
   * @param \Drupal\Core\Database\Connection $connection
   *   The database connection object.
   * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
   *   The parser to use when extracting message variables.
   */
  public function __construct(Connection $connection, LogMessageParserInterface $parser) {
    $this->connection = $connection;
    $this->parser = $parser;
  }

  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = array()) {
    $level_explode = array();
    $result = FALSE;

    // Get RFC LOg levels.
    $levels = RfcLogLevel::getLevels();

    // Get Log Filter Settings.
    $config = \Drupal::config('dblog_filter.settings');

    // Get Severity levels Configuration.
    $severity_levels = $config
      ->get('severity_levels');
    $entities_load = $config
      ->get('log_values');
    $values = array_map('trim', explode("\n", $entities_load));
    foreach ($levels as $key => $log_level) {
      $level_array[$key] = strtolower($log_level
        ->getUntranslatedString());
    }

    // Check for channel name and given values in log filter settings.
    foreach ($values as $value) {
      $explode_values = explode('|', $value);
      if ($explode_values[0] == $context['channel']) {
        $level_explode = explode(',', $explode_values[1]);
      }
    }
    if ($level_explode) {
      $result = in_array($level_array[$level], $level_explode);
    }
    if (!empty($severity_levels[$level_array[$level]])) {
      $result = TRUE;
    }

    // If present the only log message.
    if ($result) {
      parent::log($level, $message, $context);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DbLog::$connection protected property The database connection object.
DbLog::$parser protected property The message's placeholders parser.
DbLog::DEDICATED_DBLOG_CONNECTION_TARGET constant The dedicated database connection target to use for log entries.
DBLogFilter::log public function Logs with an arbitrary level. Overrides RfcLoggerTrait::log
DBLogFilter::__construct public function Constructs a DbLogFilter object. Overrides DbLog::__construct
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function