/** * Creates a syslog connection. * * @param string $configName The name of the configuration to use. * @param \YapepBase\Syslog\ISyslogConnection $connection The Syslog connection to use. * * @todo Remove the possibility to set config options. Use only the set connection [emul] */ public function __construct($configName, \YapepBase\Syslog\ISyslogConnection $connection = null) { $config = Config::getInstance(); $properties = array('applicationIdent', 'facility', 'includeSapiName', 'addPid'); foreach ($properties as $property) { try { $this->configOptions[$property] = $config->get('resource.log.' . $configName . '.' . $property, false); } catch (ConfigException $e) { // We just swallow this because we don't know what properties do we need in advance } } $this->verifyConfig($configName); if ($connection) { $this->connection = $connection; //@codeCoverageIgnoreStart } elseif (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $this->connection = new \YapepBase\Syslog\LegacySyslogConnection(); } else { $this->connection = new \YapepBase\Syslog\NativeSyslogConnection(); } //@codeCoverageIgnoreEnd $ident = $this->configOptions['applicationIdent']; if (isset($this->configOptions['includeSapiName']) && $this->configOptions['includeSapiName']) { $ident .= '-' . PHP_SAPI; } // TODO: Can be dangerous as it can override an already set value [emul] $this->connection->setIdent($ident); $this->connection->setFacility($this->configOptions['facility']); $options = 0; if (isset($this->configOptions['addPid']) && $this->configOptions['addPid']) { $options += \YapepBase\Syslog\ISyslogConnection::LOG_PID; } $this->connection->setOptions($options); $this->connection->open(); }
public function testDgramSockets() { $logPath = $this->getLogPath(); $this->object->setFacility(Syslog::LOG_USER); $this->object->setPath($logPath); $this->object->setIdent('test'); $this->initSyslogServer($logPath, true); $this->object->log(Syslog::LOG_NOTICE, 'test', 'test', mktime(15, 45, 19, 12, 6, 2011)); $this->assertEquals('<13>Dec 6 15:45:19 test: test', $this->getSyslogMessage()); $this->object->close(); $this->closeSyslogServer(); }