Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176

This commit is contained in:
Pantheon Automation 2015-08-17 17:00:26 -07:00 committed by Greg Anderson
commit 9921556621
13277 changed files with 1459781 additions and 0 deletions

View file

@ -0,0 +1,96 @@
<?php
/**
* @file
* Contains \Drupal\syslog\Logger\SysLog.
*/
namespace Drupal\syslog\Logger;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\Core\Logger\RfcLoggerTrait;
use Psr\Log\LoggerInterface;
/**
* Redirects logging messages to syslog.
*/
class SysLog implements LoggerInterface {
use RfcLoggerTrait;
/**
* A configuration object containing syslog settings.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* The message's placeholders parser.
*
* @var \Drupal\Core\Logger\LogMessageParserInterface
*/
protected $parser;
/**
* Stores whether there is a system logger connection opened or not.
*
* @var bool
*/
protected $connectionOpened = FALSE;
/**
* Constructs a SysLog object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory object.
* @param \Drupal\Core\Logger\LogMessageParserInterface $parser
* The parser to use when extracting message variables.
*/
public function __construct(ConfigFactoryInterface $config_factory, LogMessageParserInterface $parser) {
$this->config = $config_factory->get('syslog.settings');
$this->parser = $parser;
}
/**
* Opens a connection to the system logger.
*/
protected function openConnection() {
if (!$this->connectionOpened) {
$facility = $this->config->get('facility');
if ($facility === '') {
$facility = defined('LOG_LOCAL0') ? LOG_LOCAL0 : LOG_USER;
}
$this->connectionOpened = openlog($this->config->get('identity'), LOG_NDELAY, $facility);
}
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = array()) {
global $base_url;
// Ensure we have a connection available.
$this->openConnection();
// Populate the message placeholders and then replace them in the message.
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
$message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
$entry = strtr($this->config->get('format'), array(
'!base_url' => $base_url,
'!timestamp' => $context['timestamp'],
'!type' => $context['channel'],
'!ip' => $context['ip'],
'!request_uri' => $context['request_uri'],
'!referer' => $context['referer'],
'!uid' => $context['uid'],
'!link' => strip_tags($context['link']),
'!message' => strip_tags($message),
));
syslog($level, $entry);
}
}

View file

@ -0,0 +1,45 @@
<?php
/**
* @file
* Contains \Drupal\syslog\Tests\SyslogTest.
*/
namespace Drupal\syslog\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests syslog settings.
*
* @group syslog
*/
class SyslogTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('syslog');
/**
* Tests the syslog settings page.
*/
function testSettings() {
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
// If we're on Windows, there is no configuration form.
if (defined('LOG_LOCAL6')) {
$this->drupalPostForm('admin/config/development/logging', array('syslog_facility' => LOG_LOCAL6), t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$this->drupalGet('admin/config/development/logging');
if ($this->parse()) {
$field = $this->xpath('//option[@value=:value]', array(':value' => LOG_LOCAL6)); // Should be one field.
$this->assertTrue($field[0]['selected'] == 'selected', 'Facility value saved.');
}
}
}
}