mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Add syslog support (experimental)
This commit is contained in:
parent
b1f85ef41c
commit
e690ac4d1d
2 changed files with 102 additions and 22 deletions
81
rainloop/v/0.0.0/app/libraries/MailSo/Log/Drivers/Syslog.php
Normal file
81
rainloop/v/0.0.0/app/libraries/MailSo/Log/Drivers/Syslog.php
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of MailSo.
|
||||||
|
*
|
||||||
|
* (c) 2014 Usenko Timur
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace MailSo\Log\Drivers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @category MailSo
|
||||||
|
* @package Log
|
||||||
|
* @subpackage Drivers
|
||||||
|
*/
|
||||||
|
class Syslog extends \MailSo\Log\Driver
|
||||||
|
{
|
||||||
|
private $iLogLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
protected function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
|
$this->iLogLevel = \defined('LOG_INFO') ? LOG_INFO : 6;
|
||||||
|
|
||||||
|
if (\function_exists('openlog') && \function_exists('closelog') && \defined('LOG_ODELAY') && \defined('LOG_USER'))
|
||||||
|
{
|
||||||
|
\openlog('rainloop', LOG_ODELAY, LOG_USER);
|
||||||
|
|
||||||
|
\register_shutdown_function(function () {
|
||||||
|
@\closelog();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->iLogLevel = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \MailSo\Log\Drivers\Syslog
|
||||||
|
*/
|
||||||
|
public static function NewInstance()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string|array $mDesc
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function writeImplementation($mDesc)
|
||||||
|
{
|
||||||
|
if (null === $this->iLogLevel)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\is_array($mDesc))
|
||||||
|
{
|
||||||
|
$mDesc = \implode($this->sNewLine, $mDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return \syslog($this->iLogLevel, $mDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function clearImplementation()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -214,16 +214,6 @@ class Actions
|
||||||
{
|
{
|
||||||
$this->oConfig = new \RainLoop\Config\Application();
|
$this->oConfig = new \RainLoop\Config\Application();
|
||||||
|
|
||||||
// $bSave = defined('APP_INSTALLED_START');
|
|
||||||
// if (!$this->oConfig->Load())
|
|
||||||
// {
|
|
||||||
// $bSave = true;
|
|
||||||
// }
|
|
||||||
// else if (!$bSave)
|
|
||||||
// {
|
|
||||||
// $bSave = APP_VERSION !== $this->oConfig->Get('version', 'current');
|
|
||||||
// }
|
|
||||||
|
|
||||||
$bSave = defined('APP_INSTALLED_START');
|
$bSave = defined('APP_INSTALLED_START');
|
||||||
|
|
||||||
$bLoaded = $this->oConfig->Load();
|
$bLoaded = $this->oConfig->Load();
|
||||||
|
|
@ -1087,9 +1077,16 @@ class Actions
|
||||||
|
|
||||||
$this->oLogger->SetShowSecter(!$this->Config()->Get('logs', 'hide_passwords', true));
|
$this->oLogger->SetShowSecter(!$this->Config()->Get('logs', 'hide_passwords', true));
|
||||||
|
|
||||||
$sLogFileFullPath = \APP_PRIVATE_DATA.'logs/'.$this->compileLogFileName(
|
$sLogFileName = $this->Config()->Get('logs', 'filename', '');
|
||||||
$this->Config()->Get('logs', 'filename', ''));
|
|
||||||
|
|
||||||
|
$oDriver = null;
|
||||||
|
if ('syslog' === $sLogFileName)
|
||||||
|
{
|
||||||
|
$oDriver = \MailSo\Log\Drivers\Syslog::NewInstance();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sLogFileFullPath = \APP_PRIVATE_DATA.'logs/'.$this->compileLogFileName($sLogFileName);
|
||||||
$sLogFileDir = \dirname($sLogFileFullPath);
|
$sLogFileDir = \dirname($sLogFileFullPath);
|
||||||
|
|
||||||
if (!@is_dir($sLogFileDir))
|
if (!@is_dir($sLogFileDir))
|
||||||
|
|
@ -1097,8 +1094,10 @@ class Actions
|
||||||
@mkdir($sLogFileDir, 0755, true);
|
@mkdir($sLogFileDir, 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oLogger->Add(
|
$oDriver = \MailSo\Log\Drivers\File::NewInstance($sLogFileFullPath);
|
||||||
\MailSo\Log\Drivers\File::NewInstance($sLogFileFullPath)
|
}
|
||||||
|
|
||||||
|
$this->oLogger->Add($oDriver
|
||||||
->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', false))
|
->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', false))
|
||||||
->WriteOnPhpErrorOnly($this->Config()->Get('logs', 'write_on_php_error_only', false))
|
->WriteOnPhpErrorOnly($this->Config()->Get('logs', 'write_on_php_error_only', false))
|
||||||
->WriteOnTimeoutOnly($this->Config()->Get('logs', 'write_on_timeout_only', 0))
|
->WriteOnTimeoutOnly($this->Config()->Get('logs', 'write_on_timeout_only', 0))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue