You are here

final class ApigeeEdgeDebugToFileLogger in Apigee Edge 8

Logs Apigee Edge debug messages to a file in the root of Drupal.

Hierarchy

Expanded class hierarchy of ApigeeEdgeDebugToFileLogger

1 string reference to 'ApigeeEdgeDebugToFileLogger'
apigee_edge_test.services.yml in tests/modules/apigee_edge_test/apigee_edge_test.services.yml
tests/modules/apigee_edge_test/apigee_edge_test.services.yml
1 service uses ApigeeEdgeDebugToFileLogger
logger.apigee_edge_test_apigee_edge_debug_to_file in tests/modules/apigee_edge_test/apigee_edge_test.services.yml
Drupal\apigee_edge_test\Logger\ApigeeEdgeDebugToFileLogger

File

tests/modules/apigee_edge_test/src/Logger/ApigeeEdgeDebugToFileLogger.php, line 31

Namespace

Drupal\apigee_edge_test\Logger
View source
final class ApigeeEdgeDebugToFileLogger extends SysLog {

  /**
   * The database service.
   *
   * @var \Drupal\Core\Database\Connection
   */
  private $database;

  /**
   * ApigeeEdgeDebugToFileLogger constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   A configuration factory instance.
   * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
   *   The parser to use when extracting message variables.
   * @param \Drupal\Core\Database\Connection $database
   *   The database service.
   */
  public function __construct(ConfigFactoryInterface $config_factory, LogMessageParserInterface $parser, Connection $database) {
    parent::__construct($config_factory, $parser);
    $this->database = $database;
  }

  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = []) {

    // Only log messages from our debug module.
    if ($context['channel'] === 'apigee_edge_debug') {
      parent::log($level, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function syslogWrapper($level, $entry) {
    $log_path = getenv('APIGEE_EDGE_TEST_LOG_DIR');
    if (!$log_path) {
      $log_path = \Drupal::service('file_system')
        ->realpath('public://');
    }

    // Add test prefix to the log file.
    $log_path .= '/apigee_edge_debug-' . str_replace('test', '', $this->database
      ->tablePrefix()) . '.log';

    // Do not fail a test just because the fail is not writable.
    @error_log($entry . PHP_EOL, 3, $log_path);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ApigeeEdgeDebugToFileLogger::$database private property The database service.
ApigeeEdgeDebugToFileLogger::log public function Logs with an arbitrary level. Overrides SysLog::log
ApigeeEdgeDebugToFileLogger::syslogWrapper protected function A syslog wrapper to make syslog functionality testable. Overrides SysLog::syslogWrapper
ApigeeEdgeDebugToFileLogger::__construct public function ApigeeEdgeDebugToFileLogger constructor. Overrides SysLog::__construct
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
SysLog::$config protected property A configuration object containing syslog settings.
SysLog::$connectionOpened protected property Stores whether there is a system logger connection opened or not.
SysLog::$parser protected property The message's placeholders parser.
SysLog::openConnection protected function Opens a connection to the system logger.