You are here

class CleanerLogger in Cleaner 8

Class CleanerLogger.

@package Drupal\cleaner\Logger

Hierarchy

Expanded class hierarchy of CleanerLogger

1 string reference to 'CleanerLogger'
cleaner.services.yml in ./cleaner.services.yml
cleaner.services.yml
1 service uses CleanerLogger
cleaner_logger in ./cleaner.services.yml
Drupal\cleaner\Logger\CleanerLogger

File

src/Logger/CleanerLogger.php, line 12

Namespace

Drupal\cleaner\Logger
View source
class CleanerLogger {

  /**
   * Log levels array.
   *
   * @var array
   */
  private static $levels = [
    LogLevel::EMERGENCY,
    LogLevel::ALERT,
    LogLevel::CRITICAL,
    LogLevel::ERROR,
    LogLevel::WARNING,
    LogLevel::NOTICE,
    LogLevel::INFO,
    LogLevel::DEBUG,
  ];

  /**
   * Write a log into the database.
   *
   * @param string $level
   *   Log level.
   * @param string $message
   *   Log message text.
   */
  public static function log($level, $message) {
    if (!empty($message) && static::isAvailable($level)) {
      \Drupal::logger('cleaner')
        ->log($level, $message);
    }
  }

  /**
   * Check if the specified log level is available.
   *
   * @param string|null $level
   *   Log level.
   *
   * @return bool
   *   Checking result.
   */
  private static function isAvailable($level = NULL) {
    return (bool) (!empty($level) && in_array($level, static::$levels));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CleanerLogger::$levels private static property Log levels array.
CleanerLogger::isAvailable private static function Check if the specified log level is available.
CleanerLogger::log public static function Write a log into the database.