Files
sysPass/inc/SP/Log/Syslog.class.php
nuxsmin 2e432c1b6c * [ADD] PSR-3 compliance.
* [ADD] Events are now also sent to Syslog.
* [MOD] Improved file handling.
* [MOD] Improved action logging
* [FIX] Minor bugfixes
2015-10-15 02:12:33 +02:00

77 lines
2.1 KiB
PHP

<?php
/**
* sysPass
*
* @author nuxsmin
* @link http://syspass.org
* @copyright 2012-2015 Rubén Domínguez nuxsmin@syspass.org
*
* This file is part of sysPass.
*
* sysPass is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* sysPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace SP\Log;
/**
* Class Syslog para envío de mensaje al servicio de syslog
*
* @package SP\Log
*/
class Syslog extends AbstractLogger
{
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log($level, $message, array $context = array())
{
openlog("sysPass", LOG_PID, LOG_LOCAL0);
syslog($this->getSyslogLevel($level), $message);
closelog();
}
/**
* Devolver el código de nivel para la syslog
*
* @param $level string El nivel del mensaje
* @return int
*/
private function getSyslogLevel($level)
{
switch ($level) {
case LogLevel::EMERGENCY:
return LOG_EMERG;
case LogLevel::ALERT:
return LOG_ALERT;
case LogLevel::CRITICAL:
return LOG_CRIT;
case LogLevel::ERROR:
return LOG_ERR;
case LogLevel::WARNING:
return LOG_WARNING;
case LogLevel::NOTICE:
return LOG_NOTICE;
case LogLevel::INFO:
return LOG_INFO;
case LogLevel::DEBUG:
return LOG_DEBUG;
}
}
}