mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-29 11:01:34 +08:00
This commit is contained in:
parent
8a63ae05ef
commit
b8b7f10055
4 changed files with 38 additions and 14 deletions
|
@ -23,11 +23,7 @@ class File extends \MailSo\Log\Driver
|
|||
function __construct(string $sLoggerFileName)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->SetLoggerFileName($sLoggerFileName);
|
||||
}
|
||||
|
||||
public function SetLoggerFileName(string $sLoggerFileName)
|
||||
{
|
||||
$sLogFileDir = \dirname($sLoggerFileName);
|
||||
if (!\is_dir($sLogFileDir)) {
|
||||
\mkdir($sLogFileDir, 0755, true);
|
||||
|
@ -37,19 +33,14 @@ class File extends \MailSo\Log\Driver
|
|||
|
||||
protected function writeImplementation($mDesc) : bool
|
||||
{
|
||||
return $this->writeToLogFile($mDesc);
|
||||
if (\is_array($mDesc)) {
|
||||
$mDesc = \implode("\n\t", $mDesc);
|
||||
}
|
||||
return \error_log($mDesc . "\n", 3, $this->sLoggerFileName);
|
||||
}
|
||||
|
||||
protected function clearImplementation() : bool
|
||||
{
|
||||
return \unlink($this->sLoggerFileName);
|
||||
}
|
||||
|
||||
private function writeToLogFile($mDesc) : bool
|
||||
{
|
||||
if (\is_array($mDesc)) {
|
||||
$mDesc = \implode("\n\t", $mDesc);
|
||||
}
|
||||
return \error_log($mDesc . "\n", 3, $this->sLoggerFileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of MailSo.
|
||||
*
|
||||
* (c) 2023 DJMaze
|
||||
*
|
||||
* 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 StderrStream extends \MailSo\Log\Driver
|
||||
{
|
||||
protected function writeImplementation($mDesc) : bool
|
||||
{
|
||||
return 0 < \fwrite(STDERR, $mDesc . "\n");
|
||||
}
|
||||
|
||||
protected function clearImplementation() : bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -127,6 +127,8 @@ class Actions
|
|||
$sLogFileName = $this->oConfig->Get('logs', 'filename', '');
|
||||
if ('syslog' === $sLogFileName) {
|
||||
$oDriver = new \MailSo\Log\Drivers\Syslog();
|
||||
} else if ('stderr' === $sLogFileName) {
|
||||
$oDriver = new \MailSo\Log\Drivers\StderrStream();
|
||||
} else {
|
||||
$sLogFileFullPath = \trim($this->oConfig->Get('logs', 'path', '')) ?: \APP_PRIVATE_DATA . 'logs';
|
||||
\is_dir($sLogFileFullPath) || \mkdir($sLogFileFullPath, 0700, true);
|
||||
|
|
|
@ -340,7 +340,8 @@ Examples:
|
|||
filename = "log-{date:Y-m-d}.txt"
|
||||
filename = "{date:Y-m-d}/{user:domain}/{user:email}_{user:uid}.log"
|
||||
filename = "{user:email}-{date:Y-m-d}.txt"
|
||||
filename = "syslog"'),
|
||||
filename = "syslog"
|
||||
filename = "stderr"'),
|
||||
|
||||
'auth_logging' => array(false, 'Enable auth logging in a separate file (for fail2ban)'),
|
||||
'auth_logging_filename' => array('fail2ban/auth-{date:Y-m-d}.txt'),
|
||||
|
|
Loading…
Reference in a new issue