Solve the massive logger bloat by simplifying it to be RFC 5424

As it confused people and #552
This commit is contained in:
the-djmaze 2022-10-15 17:39:49 +02:00
parent 2056600a72
commit 87d01c8bde
40 changed files with 330 additions and 799 deletions

View file

@ -156,20 +156,10 @@ enable = Off
; 7 = Debug ; 7 = Debug
level = 4 level = 4
; Logs entire request only if error occured (php requred)
write_on_error_only = Off
; Logs entire request only if php error occured
write_on_php_error_only = Off
; Logs entire request only if request timeout (in seconds) occured.
write_on_timeout_only = 0
; Required for development purposes only. ; Required for development purposes only.
; Disabling this option is not recommended. ; Disabling this option is not recommended.
hide_passwords = On hide_passwords = On
time_zone = "UTC" time_zone = "UTC"
session_filter = ""
; Log filename. ; Log filename.
; For security reasons, some characters are removed from filename. ; For security reasons, some characters are removed from filename.

View file

@ -66,13 +66,13 @@ class ChangePasswordHMailServerDriver
$oHmailAccount->Save(); $oHmailAccount->Save();
$bResult = true; $bResult = true;
} else { } else {
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown account ('.$sEmail.')', \MailSo\Log\Enumerations\Type::ERROR); $this->oLogger && $this->oLogger->Write('hMailServer: Unknown account ('.$sEmail.')', \LOG_ERROR);
} }
} else { } else {
$this->oLogger && $this->oLogger->Write('hMailServer: Unknown domain ('.$sDomain.')', \MailSo\Log\Enumerations\Type::ERROR); $this->oLogger && $this->oLogger->Write('hMailServer: Unknown domain ('.$sDomain.')', \LOG_ERROR);
} }
} else { } else {
$this->oLogger && $this->oLogger->Write('hMailServer: Auth error', \MailSo\Log\Enumerations\Type::ERROR); $this->oLogger && $this->oLogger->Write('hMailServer: Auth error', \LOG_ERROR);
} }
} }
catch (\Exception $oException) catch (\Exception $oException)

View file

@ -53,7 +53,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
if ($this->bIsLoggined) { if ($this->bIsLoggined) {
$this->writeLogException( $this->writeLogException(
new \RuntimeException('Already authenticated for this session'), new \RuntimeException('Already authenticated for this session'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
try try
@ -63,7 +63,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->writeLogException($oException, \MailSo\Log\Enumerations\Type::NOTICE, true); $this->writeLogException($oException, \LOG_NOTICE, true);
} }
$this->bIsLoggined = true; $this->bIsLoggined = true;
@ -73,7 +73,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
} else { } else {
$this->writeLogException( $this->writeLogException(
new \RuntimeException('Required login'), new \RuntimeException('Required login'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
@ -125,9 +125,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
{ {
$sCommand = \trim($sCommand); $sCommand = \trim($sCommand);
if (!\strlen($sCommand)) { if (!\strlen($sCommand)) {
$this->writeLogException( $this->writeLogException(new \MailSo\Base\Exceptions\InvalidArgumentException(), \LOG_ERR, true);
new \MailSo\Base\Exceptions\InvalidArgumentException(),
\MailSo\Log\Enumerations\Type::ERROR, true);
} }
$this->IsConnected(true); $this->IsConnected(true);
@ -158,13 +156,10 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient
} }
if (!$bResult) { if (!$bResult) {
$this->writeLogException( $this->writeLogException(new \MailSo\Base\Exceptions\Exception(), \LOG_WARNING, true);
new \MailSo\Base\Exceptions\Exception(),
\MailSo\Log\Enumerations\Type::WARNING, true);
} }
$this->writeLog((\microtime(true) - $this->iRequestTime), $this->writeLog((\microtime(true) - $this->iRequestTime), \LOG_DEBUG);
\MailSo\Log\Enumerations\Type::TIME);
return $this; return $this;
} }

View file

@ -79,7 +79,7 @@ class ChangePasswordDriverLDAP
if (!\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3)) { if (!\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3)) {
$this->oLogger->Write( $this->oLogger->Write(
'Failed to set LDAP Protocol version to 3, TLS not supported.', 'Failed to set LDAP Protocol version to 3, TLS not supported.',
\MailSo\Log\Enumerations\Type::WARNING, \LOG_WARNING,
'LDAP' 'LDAP'
); );
} }

View file

@ -183,7 +183,7 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin
if ($oLogger) { if ($oLogger) {
$oLogger->Write("ERROR: {$name} password change for {$oAccount->Email()} failed"); $oLogger->Write("ERROR: {$name} password change for {$oAccount->Email()} failed");
$oLogger->WriteException($oException); $oLogger->WriteException($oException);
// $oLogger->WriteException($oException, \MailSo\Log\Enumerations\Type::WARNING, $name); // $oLogger->WriteException($oException, \LOG_WARNING, $name);
} }
} }
} }

View file

@ -202,7 +202,7 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin
$this->Manager()->IsEnabled() : bool $this->Manager()->IsEnabled() : bool
$this->Manager()->Count() : int $this->Manager()->Count() : int
$this->Manager()->SetLogger(\MailSo\Log\Logger $oLogger) : self $this->Manager()->SetLogger(\MailSo\Log\Logger $oLogger) : self
$this->Manager()->WriteLog(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO) : void $this->Manager()->WriteLog(string $sDesc, int $iType = \LOG_INFO) : void
$this->Manager()->WriteException(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO) : void $this->Manager()->WriteException(string $sDesc, int $iType = \LOG_INFO) : void
*/ */
} }

View file

@ -191,7 +191,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
$oCon = @\ldap_connect($this->sLdapUri); $oCon = @\ldap_connect($this->sLdapUri);
if ($oCon) if ($oCon)
{ {
$this->oLogger->Write('ldap_connect: connected', \MailSo\Log\Enumerations\Type::INFO, 'LDAP'); $this->oLogger->Write('ldap_connect: connected', \LOG_INFO, 'LDAP');
@\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3); @\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
@ -268,7 +268,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
$sFilter .= (1 < count($aItems) ? '(|' : '').$sSubFilter.(1 < count($aItems) ? ')' : ''); $sFilter .= (1 < count($aItems) ? '(|' : '').$sSubFilter.(1 < count($aItems) ? ')' : '');
$sFilter .= ')'; $sFilter .= ')';
$this->oLogger->Write('ldap_search: start: '.$sBaseDn.' / '.$sFilter, \MailSo\Log\Enumerations\Type::INFO, 'LDAP'); $this->oLogger->Write('ldap_search: start: '.$sBaseDn.' / '.$sFilter, \LOG_INFO, 'LDAP');
$oS = @\ldap_search($oCon, $sBaseDn, $sFilter, $aItems, 0, 30, 30); $oS = @\ldap_search($oCon, $sBaseDn, $sFilter, $aItems, 0, 30, 30);
if ($oS) if ($oS)
{ {
@ -343,7 +343,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges
$iErrno = $oCon ? @\ldap_errno($oCon) : 0; $iErrno = $oCon ? @\ldap_errno($oCon) : 0;
$this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')', $this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')',
\MailSo\Log\Enumerations\Type::WARNING, 'LDAP'); \LOG_WARNING, 'LDAP');
} }
} }

View file

@ -1,6 +1,5 @@
<?php <?php
use MailSo\Log\Enumerations\Type;
use MailSo\Log\Logger; use MailSo\Log\Logger;
use RainLoop\Model\Account; use RainLoop\Model\Account;
use RainLoop\Model\Identity; use RainLoop\Model\Identity;
@ -40,7 +39,7 @@ class LdapIdentities implements IIdentities
// Check if LDAP is available // Check if LDAP is available
if (!extension_loaded('ldap') || !function_exists('ldap_connect')) { if (!extension_loaded('ldap') || !function_exists('ldap_connect')) {
$this->ldapAvailable = false; $this->ldapAvailable = false;
$logger->Write("The LDAP extension is not available!", Type::WARNING, self::LOG_KEY); $logger->Write("The LDAP extension is not available!", \LOG_WARNING, self::LOG_KEY);
return; return;
} }
@ -77,10 +76,10 @@ class LdapIdentities implements IIdentities
} }
if (count($userResults) < 1) { if (count($userResults) < 1) {
$this->logger->Write("Could not find user $username", Type::NOTICE, self::LOG_KEY); $this->logger->Write("Could not find user $username", \LOG_NOTICE, self::LOG_KEY);
return []; return [];
} else if (count($userResults) > 1) { } else if (count($userResults) > 1) {
$this->logger->Write("Found multiple matches for user $username", Type::WARNING, self::LOG_KEY); $this->logger->Write("Found multiple matches for user $username", \LOG_WARNING, self::LOG_KEY);
} }
$userResult = $userResults[0]; $userResult = $userResults[0];
@ -219,7 +218,7 @@ class LdapIdentities implements IIdentities
$errorMsg = @ldap_error($this->ldap); $errorMsg = @ldap_error($this->ldap);
$message = empty($op) ? "LDAP Error: {$errorMsg} ({$errorNo})" : "LDAP Error during {$op}: {$errorMsg} ({$errorNo})"; $message = empty($op) ? "LDAP Error: {$errorMsg} ({$errorNo})" : "LDAP Error during {$op}: {$errorMsg} ({$errorNo})";
$this->logger->Write($message, Type::ERROR, self::LOG_KEY); $this->logger->Write($message, \LOG_ERR, self::LOG_KEY);
throw new LdapException($message, $errorNo); throw new LdapException($message, $errorNo);
} }
@ -279,14 +278,14 @@ class LdapIdentities implements IIdentities
{ {
if (!isset($entry[$attribute])) { if (!isset($entry[$attribute])) {
if ($required) if ($required)
$this->logger->Write("Attribute $attribute not found on object {$entry['dn']} while required", Type::NOTICE, self::LOG_KEY); $this->logger->Write("Attribute $attribute not found on object {$entry['dn']} while required", \LOG_NOTICE, self::LOG_KEY);
return $single ? "" : []; return $single ? "" : [];
} }
if ($single) { if ($single) {
if ($entry[$attribute]["count"] > 1) if ($entry[$attribute]["count"] > 1)
$this->logger->Write("Attribute $attribute is multivalues while only a single value is expected", Type::NOTICE, self::LOG_KEY); $this->logger->Write("Attribute $attribute is multivalues while only a single value is expected", \LOG_NOTICE, self::LOG_KEY);
return $entry[$attribute][0]; return $entry[$attribute][0];
} }

View file

@ -1,8 +1,7 @@
<?php <?php
use \MailSo\Log\Enumerations\Type; use RainLoop\Enumerations\PluginPropertyType;
use \RainLoop\Enumerations\PluginPropertyType; use RainLoop\Plugins\AbstractPlugin;
use \RainLoop\Plugins\AbstractPlugin;
use RainLoop\Plugins\Property; use RainLoop\Plugins\Property;
class LDAPLoginMappingPlugin extends AbstractPlugin class LDAPLoginMappingPlugin extends AbstractPlugin
@ -87,7 +86,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
*/ */
public function FilterLoginСredentials(&$sEmail, &$sLogin, &$sPassword) public function FilterLoginСredentials(&$sEmail, &$sLogin, &$sPassword)
{ {
$this->oLogger = \MailSo\Log\Logger::SingletonInstance(); $this->oLogger = \RainLoop\Api::Logger();
$this->aDomains = explode(',', $this->Config()->Get('plugin', 'domains', '')); $this->aDomains = explode(',', $this->Config()->Get('plugin', 'domains', ''));
$this->sSearchDomain = trim($this->Config()->Get('plugin', 'search_domain', '')); $this->sSearchDomain = trim($this->Config()->Get('plugin', 'search_domain', ''));
@ -100,13 +99,13 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
if (0 < \strlen($this->sObjectClass) && 0 < \strlen($this->sEmailField)) if (0 < \strlen($this->sObjectClass) && 0 < \strlen($this->sEmailField))
{ {
$sIP = $_SERVER['REMOTE_ADDR']; $sIP = $_SERVER['REMOTE_ADDR'];
$sResult = $this->ldapSearch($sEmail); $sResult = $this->ldapSearch($sEmail);
if ( is_array($sResult) ) { if ( is_array($sResult) ) {
$sLogin = $sResult['login']; $sLogin = $sResult['login'];
$sEmail = $sResult['email']; $sEmail = $sResult['email'];
} }
syslog(LOG_WARNING, "plugins/ldap-login-mapping/index.php:FilterLoginСredentials() auth try: $sIP/$sEmail, resolved as $sLogin/$sEmail"); syslog(LOG_WARNING, "plugins/ldap-login-mapping/index.php:FilterLoginСredentials() auth try: $sIP/$sEmail, resolved as $sLogin/$sEmail");
} }
} }
@ -163,7 +162,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
$bFound = FALSE; $bFound = FALSE;
foreach ( $this->aDomains as $sDomain ) { foreach ( $this->aDomains as $sDomain ) {
$sRegex = '/^[a-z0-9._-]+@' . preg_quote(trim($sDomain)) . '$/i'; $sRegex = '/^[a-z0-9._-]+@' . preg_quote(trim($sDomain)) . '$/i';
$this->oLogger->Write('DEBUG regex ' . $sRegex, Type::INFO, 'LDAP'); $this->oLogger->Write('DEBUG regex ' . $sRegex, \LOG_INFO, 'LDAP');
if ( preg_match($sRegex, $sEmail) === 1) { if ( preg_match($sRegex, $sEmail) === 1) {
$bFound = TRUE; $bFound = TRUE;
break; break;
@ -172,18 +171,18 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
if ( !$bFound ) { if ( !$bFound ) {
$this->oLogger->Write( $this->oLogger->Write(
'preg_match: no match in "' . $sEmail . '" for /^[a-z0-9._-]+@{configured-domains}$/i', 'preg_match: no match in "' . $sEmail . '" for /^[a-z0-9._-]+@{configured-domains}$/i',
Type::INFO, \LOG_INFO,
'LDAP'); 'LDAP');
return FALSE; return FALSE;
} }
$sLogin = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail); $sLogin = \MailSo\Base\Utils::GetAccountNameFromEmail($sEmail);
$this->oLogger->Write('ldap_connect: trying...', Type::INFO, 'LDAP'); $this->oLogger->Write('ldap_connect: trying...', \LOG_INFO, 'LDAP');
$oCon = @\ldap_connect($this->sHostName, $this->iHostPort); $oCon = @\ldap_connect($this->sHostName, $this->iHostPort);
if (!$oCon) return FALSE; if (!$oCon) return FALSE;
$this->oLogger->Write('ldap_connect: connected', Type::INFO, 'LDAP'); $this->oLogger->Write('ldap_connect: connected', \LOG_INFO, 'LDAP');
@\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3); @\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3);
@ -199,7 +198,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
} else { } else {
$sFilter = '(&(objectclass='.$this->sObjectClass.')(|('.$this->sEmailField.'='.$sEmail.')('.$this->sLoginField.'='.$sLogin.')))'; $sFilter = '(&(objectclass='.$this->sObjectClass.')(|('.$this->sEmailField.'='.$sEmail.')('.$this->sLoginField.'='.$sLogin.')))';
} }
$this->oLogger->Write('ldap_search: start: '.$sSearchDn.' / '.$sFilter, Type::INFO, 'LDAP'); $this->oLogger->Write('ldap_search: start: '.$sSearchDn.' / '.$sFilter, \LOG_INFO, 'LDAP');
$oS = @\ldap_search($oCon, $sSearchDn, $sFilter, $aItems, 0, 30, 30); $oS = @\ldap_search($oCon, $sSearchDn, $sFilter, $aItems, 0, 30, 30);
if (!$oS) { if (!$oS) {
$this->logLdapError($oCon, 'ldap_search'); $this->logLdapError($oCon, 'ldap_search');
@ -246,7 +245,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin
$iErrno = $oCon ? @\ldap_errno($oCon) : 0; $iErrno = $oCon ? @\ldap_errno($oCon) : 0;
$this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')', $this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')',
Type::WARNING, 'LDAP'); \LOG_WARNING, 'LDAP');
} }
} }

View file

@ -194,7 +194,7 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
} }
catch (\Exception $oException) catch (\Exception $oException)
{ {
$oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $oActions->Logger()->WriteException($oException, \LOG_ERR);
} }
} }
@ -292,7 +292,7 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin
} }
catch (\Exception $oException) catch (\Exception $oException)
{ {
$oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $oActions->Logger()->WriteException($oException, \LOG_ERR);
} }
$oActions = \RainLoop::Actions(); $oActions = \RainLoop::Actions();

View file

@ -802,7 +802,7 @@ abstract class Utils
return false; return false;
} }
public static function ClearArrayUtf8Values(array &$aInput) private static function ClearArrayUtf8Values(array &$aInput)
{ {
foreach ($aInput as $mKey => $mItem) foreach ($aInput as $mKey => $mItem)
{ {
@ -824,35 +824,20 @@ abstract class Utils
public static function Php2js($mInput, ?\MailSo\Log\Logger $oLogger = null) : string public static function Php2js($mInput, ?\MailSo\Log\Logger $oLogger = null) : string
{ {
$sResult = \json_encode($mInput, JSON_UNESCAPED_UNICODE); $sResult = \json_encode($mInput, JSON_UNESCAPED_UNICODE);
if (!\is_string($sResult) || '' === $sResult) if (!\is_string($sResult) || '' === $sResult) {
{ \trigger_error(
if (!$oLogger && \MailSo\Log\Logger::IsSystemEnabled()) 'json_encode: '.\trim(
{ (static::FunctionExistsAndEnabled('json_last_error') ? ' [Error Code: '.\json_last_error().']' : '').
$oLogger = \MailSo\Config::$SystemLogger; (static::FunctionExistsAndEnabled('json_last_error_msg') ? ' [Error Message: '.\json_last_error_msg().']' : '')
} ), E_USER_WARNING
);
if ($oLogger) if (\is_array($mInput)) {
{ // $oLogger->WriteDump($mInput, \LOG_INFO, 'JSON');
$oLogger->Write('json_encode: '.\trim( // $oLogger->Write('Trying to clear Utf8 before json_encode', \LOG_INFO, 'JSON');
(static::FunctionExistsAndEnabled('json_last_error') ? ' [Error Code: '.\json_last_error().']' : '').
(static::FunctionExistsAndEnabled('json_last_error_msg') ? ' [Error Message: '.\json_last_error_msg().']' : '')
), \MailSo\Log\Enumerations\Type::WARNING, 'JSON'
);
}
if (\is_array($mInput))
{
if ($oLogger)
{
$oLogger->WriteDump($mInput, \MailSo\Log\Enumerations\Type::INFO, 'JSON');
$oLogger->Write('Trying to clear Utf8 before json_encode', \MailSo\Log\Enumerations\Type::INFO, 'JSON');
}
static::ClearArrayUtf8Values($mInput); static::ClearArrayUtf8Values($mInput);
$sResult = \json_encode($mInput, JSON_UNESCAPED_UNICODE); $sResult = \json_encode($mInput, JSON_UNESCAPED_UNICODE);
} }
} }
return $sResult; return $sResult;
} }

View file

@ -70,9 +70,4 @@ class Config
* @var int * @var int
*/ */
public static $ImapTimeout = 300; public static $ImapTimeout = 300;
/**
* @var \MailSo\Log\Logger|null
*/
public static $SystemLogger = null;
} }

View file

@ -508,11 +508,11 @@ trait Folders
} }
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException) catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException)
{ {
$this->writeLogException($oException, \MailSo\Log\Enumerations\Type::WARNING, false); $this->writeLogException($oException, \LOG_WARNING, false);
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->writeLogException($oException, \MailSo\Log\Enumerations\Type::WARNING, false); $this->writeLogException($oException, \LOG_WARNING, false);
} }
} }
} }

View file

@ -17,7 +17,6 @@ use MailSo\Imap\Enumerations\FetchType;
use MailSo\Imap\ResponseCollection; use MailSo\Imap\ResponseCollection;
use MailSo\Imap\SequenceSet; use MailSo\Imap\SequenceSet;
use MailSo\Imap\Enumerations\ResponseType; use MailSo\Imap\Enumerations\ResponseType;
use MailSo\Log\Enumerations\Type as LogType;
use MailSo\Base\Exceptions\InvalidArgumentException; use MailSo\Base\Exceptions\InvalidArgumentException;
/** /**
@ -35,7 +34,7 @@ trait Messages
{ {
if (!\strlen(\trim($sIndexRange))) if (!\strlen(\trim($sIndexRange)))
{ {
$this->writeLogException(new InvalidArgumentException, LogType::ERROR, true); $this->writeLogException(new InvalidArgumentException, \LOG_ERR, true);
} }
$aReturn = array(); $aReturn = array();
@ -115,7 +114,7 @@ trait Messages
if (FetchResponse::hasUidAndSize($oResponse)) { if (FetchResponse::hasUidAndSize($oResponse)) {
$aReturn[] = new FetchResponse($oResponse); $aReturn[] = new FetchResponse($oResponse);
} else if ($this->oLogger) { } else if ($this->oLogger) {
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse.']', LogType::NOTICE); $this->oLogger->Write('Skipped Imap Response! ['.$oResponse.']', \LOG_NOTICE);
} }
} }
} }
@ -160,7 +159,7 @@ trait Messages
private function writeMessageStream($rMessageStream) : ?int private function writeMessageStream($rMessageStream) : ?int
{ {
$this->writeLog('Write to connection stream', LogType::NOTE); $this->writeLog('Write to connection stream', \LOG_INFO);
\MailSo\Base\Utils::MultipleStreamWriter($rMessageStream, array($this->ConnectionResource())); \MailSo\Base\Utils::MultipleStreamWriter($rMessageStream, array($this->ConnectionResource()));
@ -198,7 +197,7 @@ trait Messages
public function MessageCopy(string $sToFolder, SequenceSet $oRange) : ResponseCollection public function MessageCopy(string $sToFolder, SequenceSet $oRange) : ResponseCollection
{ {
if (!\count($oRange)) { if (!\count($oRange)) {
$this->writeLogException(new InvalidArgumentException, LogType::ERROR, true); $this->writeLogException(new InvalidArgumentException, \LOG_ERR, true);
} }
return $this->SendRequestGetResponse( return $this->SendRequestGetResponse(
@ -215,13 +214,13 @@ trait Messages
public function MessageMove(string $sToFolder, SequenceSet $oRange) : ResponseCollection public function MessageMove(string $sToFolder, SequenceSet $oRange) : ResponseCollection
{ {
if (!\count($oRange)) { if (!\count($oRange)) {
$this->writeLogException(new InvalidArgumentException, LogType::ERROR, true); $this->writeLogException(new InvalidArgumentException, \LOG_ERR, true);
} }
if (!$this->IsSupported('MOVE')) { if (!$this->IsSupported('MOVE')) {
$this->writeLogException( $this->writeLogException(
new \MailSo\IMAP\Exceptions\RuntimeException('Move is not supported'), new \MailSo\IMAP\Exceptions\RuntimeException('Move is not supported'),
LogType::ERROR, true); \LOG_ERR, true);
} }
return $this->SendRequestGetResponse( return $this->SendRequestGetResponse(

View file

@ -103,7 +103,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'), new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
} }
@ -128,7 +128,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException, new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->sLogginedUser = $sLogin; $this->sLogginedUser = $sLogin;
@ -199,7 +199,7 @@ class ImapClient extends \MailSo\Net\NetClient
if ($oR && Enumerations\ResponseType::CONTINUATION === $oR->ResponseType) { if ($oR && Enumerations\ResponseType::CONTINUATION === $oR->ResponseType) {
if (!empty($oR->ResponseList[1]) && preg_match('/^[a-zA-Z0-9=+\/]+$/', $oR->ResponseList[1])) { if (!empty($oR->ResponseList[1]) && preg_match('/^[a-zA-Z0-9=+\/]+$/', $oR->ResponseList[1])) {
$this->Logger()->Write(\base64_decode($oR->ResponseList[1]), $this->Logger()->Write(\base64_decode($oR->ResponseList[1]),
\MailSo\Log\Enumerations\Type::WARNING); \LOG_WARNING);
} }
$this->sendRaw(''); $this->sendRaw('');
$oResponse = $this->getResponse(); $oResponse = $this->getResponse();
@ -254,7 +254,7 @@ class ImapClient extends \MailSo\Net\NetClient
$this->writeLogException( $this->writeLogException(
new Exceptions\LoginBadCredentialsException( new Exceptions\LoginBadCredentialsException(
$oException->GetResponses(), '', 0, $oException), $oException->GetResponses(), '', 0, $oException),
\MailSo\Log\Enumerations\Type::NOTICE, true); \LOG_NOTICE, true);
} }
$this->bIsLoggined = true; $this->bIsLoggined = true;
@ -364,7 +364,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
throw new Exceptions\ResponseException; throw new Exceptions\ResponseException;
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->writeLogException($e, \MailSo\Log\Enumerations\Type::ERROR); $this->writeLogException($e, \LOG_ERR);
throw $e; throw $e;
} }
} }
@ -409,7 +409,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException, new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->IsConnected(true); $this->IsConnected(true);
@ -475,11 +475,11 @@ class ImapClient extends \MailSo\Net\NetClient
} }
$this->writeLogException( $this->writeLogException(
new Exceptions\LoginException, new Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::NOTICE, true); \LOG_NOTICE, true);
} }
$this->writeLogException( $this->writeLogException(
new Exceptions\LoginException, new Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::NOTICE, true); \LOG_NOTICE, true);
} }
/** /**
@ -509,7 +509,7 @@ class ImapClient extends \MailSo\Net\NetClient
exit; exit;
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING); $this->writeLogException($e, \LOG_WARNING);
throw $e; throw $e;
} }
} }
@ -534,8 +534,7 @@ class ImapClient extends \MailSo\Net\NetClient
if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) { if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) {
if (isset($this->aTagTimeouts[$sEndTag])) { if (isset($this->aTagTimeouts[$sEndTag])) {
$this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', $this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', \LOG_DEBUG);
\MailSo\Log\Enumerations\Type::TIME);
unset($this->aTagTimeouts[$sEndTag]); unset($this->aTagTimeouts[$sEndTag]);
} }
@ -548,7 +547,7 @@ class ImapClient extends \MailSo\Net\NetClient
$oResult->validate(); $oResult->validate();
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING); $this->writeLogException($e, \LOG_WARNING);
throw $e; throw $e;
} }
@ -580,8 +579,7 @@ class ImapClient extends \MailSo\Net\NetClient
if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) { if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) {
if (isset($this->aTagTimeouts[$sEndTag])) { if (isset($this->aTagTimeouts[$sEndTag])) {
$this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', $this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', \LOG_DEBUG);
\MailSo\Log\Enumerations\Type::TIME);
unset($this->aTagTimeouts[$sEndTag]); unset($this->aTagTimeouts[$sEndTag]);
} }
@ -594,7 +592,7 @@ class ImapClient extends \MailSo\Net\NetClient
$oResult->validate(); $oResult->validate();
} catch (\Throwable $e) { } catch (\Throwable $e) {
$this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING); $this->writeLogException($e, \LOG_WARNING);
throw $e; throw $e;
} }
} }

View file

@ -13,7 +13,6 @@
namespace MailSo\Imap\Requests; namespace MailSo\Imap\Requests;
use MailSo\Imap\Exceptions\RuntimeException; use MailSo\Imap\Exceptions\RuntimeException;
use MailSo\Log\Enumerations\Type;
/** /**
* @category MailSo * @category MailSo
@ -58,7 +57,7 @@ class ESEARCH extends Request
if (!$oImapClient->IsSupported('ESEARCH')) { if (!$oImapClient->IsSupported('ESEARCH')) {
$oImapClient->writeLogException( $oImapClient->writeLogException(
new RuntimeException('ESEARCH is not supported'), new RuntimeException('ESEARCH is not supported'),
Type::ERROR, true); \LOG_ERR, true);
} }
parent::__construct($oImapClient); parent::__construct($oImapClient);
} }
@ -72,7 +71,7 @@ class ESEARCH extends Request
if (false !== \stripos($this->sCriterias, 'FUZZY') && !$this->oImapClient->IsSupported('SEARCH=FUZZY')) { if (false !== \stripos($this->sCriterias, 'FUZZY') && !$this->oImapClient->IsSupported('SEARCH=FUZZY')) {
$this->oImapClient->writeLogException( $this->oImapClient->writeLogException(
new RuntimeException('SEARCH=FUZZY is not supported'), new RuntimeException('SEARCH=FUZZY is not supported'),
Type::ERROR, true); \LOG_ERR, true);
} }
*/ */
@ -93,7 +92,7 @@ class ESEARCH extends Request
if (!$this->oImapClient->IsSupported('MULTISEARCH')) { if (!$this->oImapClient->IsSupported('MULTISEARCH')) {
$this->oImapClient->writeLogException( $this->oImapClient->writeLogException(
new RuntimeException('MULTISEARCH is not supported'), new RuntimeException('MULTISEARCH is not supported'),
Type::ERROR, true); \LOG_ERR, true);
} }
$sCmd = 'ESEARCH'; $sCmd = 'ESEARCH';
$aReques[] = 'IN'; $aReques[] = 'IN';
@ -113,7 +112,7 @@ class ESEARCH extends Request
if (\preg_match('/PARTIAL|UPDATE|CONTEXT/i', $sReturn)) { if (\preg_match('/PARTIAL|UPDATE|CONTEXT/i', $sReturn)) {
$this->oImapClient->writeLogException( $this->oImapClient->writeLogException(
new RuntimeException('CONTEXT=SEARCH is not supported'), new RuntimeException('CONTEXT=SEARCH is not supported'),
Type::ERROR, true); \LOG_ERR, true);
} }
} }
} }

View file

@ -16,7 +16,6 @@
namespace MailSo\Imap\Requests; namespace MailSo\Imap\Requests;
use MailSo\Imap\Exceptions\RuntimeException; use MailSo\Imap\Exceptions\RuntimeException;
use MailSo\Log\Enumerations\Type;
/** /**
* @category MailSo * @category MailSo
@ -59,7 +58,7 @@ class SORT extends Request
if (!$oImapClient->IsSupported('SORT')) { if (!$oImapClient->IsSupported('SORT')) {
$oImapClient->writeLogException( $oImapClient->writeLogException(
new RuntimeException('SORT is not supported'), new RuntimeException('SORT is not supported'),
Type::ERROR, true); \LOG_ERR, true);
} }
parent::__construct($oImapClient); parent::__construct($oImapClient);
} }
@ -69,7 +68,7 @@ class SORT extends Request
if (!$this->aSortTypes) { if (!$this->aSortTypes) {
$this->oImapClient->writeLogException( $this->oImapClient->writeLogException(
new RuntimeException('SortTypes are missing'), new RuntimeException('SortTypes are missing'),
Type::ERROR, true); \LOG_ERR, true);
} }
$aRequest = array(); $aRequest = array();
@ -79,14 +78,14 @@ class SORT extends Request
if (!$this->oImapClient->IsSupported('ESORT')) { if (!$this->oImapClient->IsSupported('ESORT')) {
$this->oImapClient->writeLogException( $this->oImapClient->writeLogException(
new RuntimeException('ESORT is not supported'), new RuntimeException('ESORT is not supported'),
Type::ERROR, true); \LOG_ERR, true);
} }
if (!$this->oImapClient->IsSupported('CONTEXT=SORT')) { if (!$this->oImapClient->IsSupported('CONTEXT=SORT')) {
foreach ($this->aReturn as $sReturn) { foreach ($this->aReturn as $sReturn) {
if (\preg_match('/PARTIAL|UPDATE|CONTEXT/i', $sReturn)) { if (\preg_match('/PARTIAL|UPDATE|CONTEXT/i', $sReturn)) {
$this->oImapClient->writeLogException( $this->oImapClient->writeLogException(
new RuntimeException('CONTEXT=SORT is not supported'), new RuntimeException('CONTEXT=SORT is not supported'),
Type::ERROR, true); \LOG_ERR, true);
} }
} }
} }

View file

@ -36,7 +36,7 @@ class THREAD extends Request
} else { } else {
$oImapClient->writeLogException( $oImapClient->writeLogException(
new \MailSo\Imap\Exceptions\RuntimeException('THREAD is not supported'), new \MailSo\Imap\Exceptions\RuntimeException('THREAD is not supported'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
parent::__construct($oImapClient); parent::__construct($oImapClient);
} }
@ -46,7 +46,7 @@ class THREAD extends Request
if (!$this->oImapClient->IsSupported(\strtoupper("THREAD={$this->sAlgorithm}"))) { if (!$this->oImapClient->IsSupported(\strtoupper("THREAD={$this->sAlgorithm}"))) {
$this->oImapClient->writeLogException( $this->oImapClient->writeLogException(
new \MailSo\Imap\Exceptions\RuntimeException("THREAD={$this->sAlgorithm} is not supported"), new \MailSo\Imap\Exceptions\RuntimeException("THREAD={$this->sAlgorithm} is not supported"),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->oImapClient->SendRequest( $this->oImapClient->SendRequest(

View file

@ -184,14 +184,14 @@ trait ResponseParser
if (!$bTreatAsAtom) { if (!$bTreatAsAtom) {
$aList[] = $sLiteral; $aList[] = $sLiteral;
if (\MailSo\Config::$LogSimpleLiterals) { if (\MailSo\Config::$LogSimpleLiterals) {
$this->writeLog('{'.$iLiteralLen.'} '.$sLiteral, \MailSo\Log\Enumerations\Type::INFO); $this->writeLog('{'.$iLiteralLen.'} '.$sLiteral, \LOG_INFO);
} }
} else { } else {
\SnappyMail\Log::notice('IMAP', 'Literal treated as atom and skipped'); \SnappyMail\Log::notice('IMAP', 'Literal treated as atom and skipped');
} }
unset($sLiteral); unset($sLiteral);
} else { } else {
$this->writeLog('Can\'t read imap stream', \MailSo\Log\Enumerations\Type::NOTE); $this->writeLog('Can\'t read imap stream', \LOG_WARNING);
} }
} }
@ -359,7 +359,7 @@ trait ResponseParser
$iBLen = \strlen($sAddRead); $iBLen = \strlen($sAddRead);
if (!$iBLen) { if (!$iBLen) {
$this->writeLog('Literal stream read warning "read '.\strlen($sLiteral).' of '. $this->writeLog('Literal stream read warning "read '.\strlen($sLiteral).' of '.
$iLiteralLen.'" bytes', \MailSo\Log\Enumerations\Type::WARNING); $iLiteralLen.'" bytes', \LOG_WARNING);
return null; return null;
} }
$sLiteral .= $sAddRead; $sLiteral .= $sAddRead;
@ -373,7 +373,7 @@ trait ResponseParser
$iLiteralSize = \strlen($sLiteral); $iLiteralSize = \strlen($sLiteral);
if ($iLiteralLen !== $iLiteralSize) { if ($iLiteralLen !== $iLiteralSize) {
$this->writeLog('Literal stream read warning "read '.$iLiteralSize.' of '. $this->writeLog('Literal stream read warning "read '.$iLiteralSize.' of '.
$iLiteralLen.'" bytes', \MailSo\Log\Enumerations\Type::WARNING); $iLiteralLen.'" bytes', \LOG_WARNING);
} }
return $sLiteral; return $sLiteral;
} }
@ -403,7 +403,7 @@ trait ResponseParser
\MailSo\Base\StreamWrappers\Literal::CreateStream($this->ConnectionResource(), $iLiteralLen); \MailSo\Base\StreamWrappers\Literal::CreateStream($this->ConnectionResource(), $iLiteralLen);
$this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase. $this->writeLog('Start Callback for '.$sParent.' / '.$sLiteralAtomUpperCase.
' - try to read '.$iLiteralLen.' bytes.', \MailSo\Log\Enumerations\Type::NOTE); ' - try to read '.$iLiteralLen.' bytes.', \LOG_INFO);
$this->bRunningCallback = true; $this->bRunningCallback = true;
@ -413,7 +413,6 @@ trait ResponseParser
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->writeLog('Callback Exception', \MailSo\Log\Enumerations\Type::NOTICE);
$this->writeLogException($oException); $this->writeLogException($oException);
} }
@ -423,7 +422,7 @@ trait ResponseParser
$bFeof = \feof($rImapLiteralStream); $bFeof = \feof($rImapLiteralStream);
$this->writeLog('End Callback for '.$sParent.' / '.$sLiteralAtomUpperCase. $this->writeLog('End Callback for '.$sParent.' / '.$sLiteralAtomUpperCase.
' - feof = '.($bFeof ? 'good' : 'BAD'), $bFeof ? ' - feof = '.($bFeof ? 'good' : 'BAD'), $bFeof ?
\MailSo\Log\Enumerations\Type::NOTE : \MailSo\Log\Enumerations\Type::WARNING); \LOG_INFO : \LOG_WARNING);
if (!$bFeof) { if (!$bFeof) {
while (!\feof($rImapLiteralStream)) { while (!\feof($rImapLiteralStream)) {
@ -445,11 +444,11 @@ trait ResponseParser
if (0 < $iNotReadLiteralLen) { if (0 < $iNotReadLiteralLen) {
$this->writeLog('Not read literal size is '.$iNotReadLiteralLen.' bytes.', $this->writeLog('Not read literal size is '.$iNotReadLiteralLen.' bytes.',
\MailSo\Log\Enumerations\Type::WARNING); \LOG_WARNING);
} }
} else { } else {
$this->writeLog('Literal stream is not resource after callback.', $this->writeLog('Literal stream is not resource after callback.',
\MailSo\Log\Enumerations\Type::WARNING); \LOG_WARNING);
} }
$this->bRunningCallback = false; $this->bRunningCallback = false;

View file

@ -20,22 +20,31 @@ abstract class Driver
/** /**
* @var string * @var string
*/ */
protected $sDatePattern; protected $sDatePattern = 'H:i:s';
/** /**
* @var string * @var string
*/ */
protected $sName; protected $sName = '';
/** /**
* @var array * @var array
*/ */
protected $aPrefixes; const PREFIXES = [
\LOG_EMERG => '[EMERGENCY]',
\LOG_ALERT => '[ALERT]',
\LOG_CRIT => '[CRITICAL]',
\LOG_ERR => '[ERROR]',
\LOG_WARNING => '[WARNING]',
\LOG_NOTICE => '[NOTICE]',
\LOG_INFO => '[INFO]',
\LOG_DEBUG => '[DEBUG]'
];
/** /**
* @var bool * @var bool
*/ */
protected $bGuidPrefix; protected $bGuidPrefix = true;
/** /**
* @var DateTimeZone * @var DateTimeZone
@ -45,85 +54,23 @@ abstract class Driver
/** /**
* @var bool * @var bool
*/ */
protected $bTimePrefix; protected $bTimePrefix = true;
/** /**
* @var bool * @var bool
*/ */
protected $bTypedPrefix; protected $bTypedPrefix = true;
/**
* @var string
*/
protected $sNewLine;
/**
* @var int
*/
private $iWriteOnTimeoutOnly;
/**
* @var bool
*/
private $bWriteOnErrorOnly;
/**
* @var bool
*/
private $bWriteOnPhpErrorOnly;
/**
* @var bool
*/
private $bFlushCache;
/**
* @var array
*/
private $aCache;
function __construct() function __construct()
{ {
$this->sDatePattern = 'H:i:s';
$this->sName = 'INFO';
$this->sNewLine = "\r\n";
$this->bTimePrefix = true;
$this->bTypedPrefix = true;
$this->bGuidPrefix = true;
$this->oTimeZone = new \DateTimeZone('UTC'); $this->oTimeZone = new \DateTimeZone('UTC');
$this->iWriteOnTimeoutOnly = 0;
$this->bWriteOnErrorOnly = false;
$this->bWriteOnPhpErrorOnly = false;
$this->bFlushCache = false;
$this->aCache = array();
$this->aPrefixes = array(
\MailSo\Log\Enumerations\Type::DEBUG => '[DEBUG]',
\MailSo\Log\Enumerations\Type::INFO => '[DATA]',
\MailSo\Log\Enumerations\Type::SECURE => '[SECURE]',
\MailSo\Log\Enumerations\Type::NOTE => '[NOTE]',
\MailSo\Log\Enumerations\Type::TIME => '[TIME]',
\MailSo\Log\Enumerations\Type::TIME_DELTA => '[TIME]',
\MailSo\Log\Enumerations\Type::MEMORY => '[MEMORY]',
\MailSo\Log\Enumerations\Type::NOTICE => '[NOTICE]',
\MailSo\Log\Enumerations\Type::WARNING => '[WARNING]',
\MailSo\Log\Enumerations\Type::ERROR => '[ERROR]',
\MailSo\Log\Enumerations\Type::NOTICE_PHP => '[NOTICE]',
\MailSo\Log\Enumerations\Type::WARNING_PHP => '[WARNING]',
\MailSo\Log\Enumerations\Type::ERROR_PHP => '[ERROR]',
);
} }
public function SetTimeZone(/*\DateTimeZone | string*/ $oTimeZone) : self public function SetTimeZone(/*\DateTimeZone | string*/ $mTimeZone) : self
{ {
if ($oTimeZone instanceof \DateTimeZone) { $this->oTimeZone = $mTimeZone instanceof \DateTimeZone
$this->oTimeZone = $oTimeZone; ? $mTimeZone
} else { : new \DateTimeZone($mTimeZone);
$this->oTimeZone = new \DateTimeZone($oTimeZone);
}
return $this; return $this;
} }
@ -139,24 +86,6 @@ abstract class Driver
return $this; return $this;
} }
public function WriteOnErrorOnly(bool $bValue) : self
{
$this->bWriteOnErrorOnly = $bValue;
return $this;
}
public function WriteOnPhpErrorOnly(bool $bValue) : self
{
$this->bWriteOnPhpErrorOnly = $bValue;
return $this;
}
public function WriteOnTimeoutOnly(int $iTimeout) : self
{
$this->iWriteOnTimeoutOnly = \max(0, (int) $iTimeout);
return $this;
}
public function DisableTypedPrefix() : self public function DisableTypedPrefix() : self
{ {
$this->bTypedPrefix = false; $this->bTypedPrefix = false;
@ -165,21 +94,6 @@ abstract class Driver
abstract protected function writeImplementation($mDesc) : bool; abstract protected function writeImplementation($mDesc) : bool;
protected function writeEmptyLineImplementation() : bool
{
return $this->writeImplementation('');
}
protected function loggerLineImplementation(string $sTimePrefix, string $sDesc,
int $iType = \MailSo\Log\Enumerations\Type::INFO, string $sName = '') : string
{
return \ltrim(
($this->bTimePrefix ? '['.$sTimePrefix.']' : '').
($this->bGuidPrefix ? '['.Logger::Guid().']' : '').
($this->bTypedPrefix ? ' '.$this->getTypedPrefix($iType, $sName) : '')
).$sDesc;
}
protected function clearImplementation() : bool protected function clearImplementation() : bool
{ {
return true; return true;
@ -193,129 +107,24 @@ abstract class Driver
protected function getTypedPrefix(int $iType, string $sName = '') : string protected function getTypedPrefix(int $iType, string $sName = '') : string
{ {
$sName = \strlen($sName) ? $sName : $this->sName; $sName = \strlen($sName) ? $sName : $this->sName;
return isset($this->aPrefixes[$iType]) ? $sName.$this->aPrefixes[$iType].': ' : ''; return isset(self::PREFIXES[$iType]) ? $sName . self::PREFIXES[$iType].': ' : '';
} }
protected function localWriteImplementation($mDesc, bool $bDiplayCrLf = false) : string final public function Write(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bDiplayCrLf = false)
{ {
if ($bDiplayCrLf) $sDesc = \ltrim(
{ ($this->bTimePrefix ? '['.$this->getTimeWithMicroSec().']' : '').
if (\is_array($mDesc)) ($this->bGuidPrefix ? '['.Logger::Guid().']' : '').
{ ($this->bTypedPrefix ? ' '.$this->getTypedPrefix($iType, $sName) : '')
foreach ($mDesc as &$sLine) ) . $sDesc;
{ if ($bDiplayCrLf) {
$sLine = \strtr($sLine, array("\r" => '\r', "\n" => '\n'.$this->sNewLine)); $sDesc = \rtrim(\strtr($sDesc, array("\r" => '\r', "\n" => '\n'."\n")));
$sLine = \rtrim($sLine);
}
}
else
{
$mDesc = \strtr($mDesc, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$mDesc = \rtrim($mDesc);
}
} }
return $this->writeImplementation($sDesc);
return $this->writeImplementation($mDesc);
}
final public function Write(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO, string $sName = '', bool $bDiplayCrLf = false)
{
$bResult = true;
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || $this->iWriteOnTimeoutOnly))
{
$bErrorPhp = false;
$bError = $this->bWriteOnErrorOnly && \in_array($iType, array(
\MailSo\Log\Enumerations\Type::NOTICE,
\MailSo\Log\Enumerations\Type::NOTICE_PHP,
\MailSo\Log\Enumerations\Type::WARNING,
\MailSo\Log\Enumerations\Type::WARNING_PHP,
\MailSo\Log\Enumerations\Type::ERROR,
\MailSo\Log\Enumerations\Type::ERROR_PHP
));
if (!$bError)
{
$bErrorPhp = $this->bWriteOnPhpErrorOnly && \in_array($iType, array(
\MailSo\Log\Enumerations\Type::NOTICE_PHP,
\MailSo\Log\Enumerations\Type::WARNING_PHP,
\MailSo\Log\Enumerations\Type::ERROR_PHP
));
}
if ($bError || $bErrorPhp)
{
$sFlush = '--- FlushLogCache: '.($bError ? 'WriteOnErrorOnly' : 'WriteOnPhpErrorOnly');
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
\array_unshift($this->aCache, '');
}
else
{
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else if ($this->iWriteOnTimeoutOnly && \time() - $_SERVER['REQUEST_TIME_FLOAT'] > $this->iWriteOnTimeoutOnly)
{
$sFlush = '--- FlushLogCache: WriteOnTimeoutOnly ['.(\time() - $_SERVER['REQUEST_TIME_FLOAT']).'sec]';
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
\array_unshift($this->aCache, '');
}
else
{
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else
{
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
}
}
else
{
$bResult = $this->localWriteImplementation(
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName), $bDiplayCrLf);
}
return $bResult;
}
public function GetNewLine() : string
{
return $this->sNewLine;
} }
final public function Clear() : bool final public function Clear() : bool
{ {
return $this->clearImplementation(); return $this->clearImplementation();
} }
final public function WriteEmptyLine() : void
{
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || $this->iWriteOnTimeoutOnly))
{
$this->aCache[] = '';
}
else
{
$this->writeEmptyLineImplementation();
}
}
} }

View file

@ -1,62 +0,0 @@
<?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 Callback extends \MailSo\Log\Driver
{
/**
* @var mixed
*/
private $fWriteCallback;
/**
* @var mixed
*/
private $fClearCallback;
/**
* @param mixed $fWriteCallback
* @param mixed $fClearCallback
*/
function __construct($fWriteCallback, $fClearCallback)
{
parent::__construct();
$this->fWriteCallback = \is_callable($fWriteCallback) ? $fWriteCallback : null;
$this->fClearCallback = \is_callable($fClearCallback) ? $fClearCallback : null;
}
protected function writeImplementation($mDesc) : bool
{
if ($this->fWriteCallback)
{
($this->fWriteCallback)($mDesc);
}
return true;
}
protected function clearImplementation() : bool
{
if ($this->fClearCallback)
{
($this->fClearCallback)();
}
return true;
}
}

View file

@ -23,16 +23,18 @@ class File extends \MailSo\Log\Driver
*/ */
private $sLoggerFileName; private $sLoggerFileName;
function __construct(string $sLoggerFileName, string $sNewLine = "\r\n") function __construct(string $sLoggerFileName)
{ {
parent::__construct(); parent::__construct();
$this->SetLoggerFileName($sLoggerFileName);
$this->sLoggerFileName = $sLoggerFileName;
$this->sNewLine = $sNewLine;
} }
public function SetLoggerFileName(string $sLoggerFileName) public function SetLoggerFileName(string $sLoggerFileName)
{ {
$sLogFileDir = \dirname($sLoggerFileName);
if (!\is_dir($sLogFileDir)) {
\mkdir($sLogFileDir, 0755, true);
}
$this->sLoggerFileName = $sLoggerFileName; $this->sLoggerFileName = $sLoggerFileName;
} }
@ -48,11 +50,9 @@ class File extends \MailSo\Log\Driver
private function writeToLogFile($mDesc) : bool private function writeToLogFile($mDesc) : bool
{ {
if (\is_array($mDesc)) if (\is_array($mDesc)) {
{ $mDesc = \implode("\n\t", $mDesc);
$mDesc = \implode($this->sNewLine, $mDesc);
} }
return \error_log($mDesc . "\n", 3, $this->sLoggerFileName);
return \error_log($mDesc.$this->sNewLine, 3, $this->sLoggerFileName);
} }
} }

View file

@ -1,64 +0,0 @@
<?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 Inline extends \MailSo\Log\Driver
{
/**
* @var bool
*/
private $bHtmlEncodeSpecialChars;
function __construct(string $sNewLine = "\r\n", bool $bHtmlEncodeSpecialChars = false)
{
parent::__construct();
$this->sNewLine = $sNewLine;
$this->bHtmlEncodeSpecialChars = $bHtmlEncodeSpecialChars;
}
protected function writeImplementation($mDesc) : bool
{
if (\is_array($mDesc))
{
if ($this->bHtmlEncodeSpecialChars)
{
$mDesc = \array_map(function ($sItem) {
return \htmlspecialchars($sItem);
}, $mDesc);
}
$mDesc = \implode($this->sNewLine, $mDesc);
}
else
{
echo ($this->bHtmlEncodeSpecialChars) ? \htmlspecialchars($mDesc).$this->sNewLine : $mDesc.$this->sNewLine;
}
return true;
}
protected function clearImplementation() : bool
{
if (\defined('PHP_SAPI') && 'cli' === PHP_SAPI && \MailSo\Base\Utils::FunctionExistsAndEnabled('system'))
{
\system('clear');
}
return true;
}
}

View file

@ -19,18 +19,14 @@ namespace MailSo\Log\Enumerations;
abstract class Type abstract class Type
{ {
const const
INFO = 0, INFO = \LOG_INFO, // 6
NOTICE = 1, NOTICE = \LOG_NOTICE, // 5
WARNING = 2, WARNING = \LOG_WARNING, // 4
ERROR = 3, ERROR = \LOG_ERR, // 3
SECURE = 4, SECURE = \LOG_INFO,
NOTE = 5, NOTE = \LOG_INFO,
TIME = 6, TIME = \LOG_DEBUG,
MEMORY = 7, MEMORY = \LOG_INFO,
TIME_DELTA = 8, TIME_DELTA = \LOG_INFO,
DEBUG = 9, DEBUG = \LOG_DEBUG; // 7
NOTICE_PHP = 11,
WARNING_PHP = 12,
ERROR_PHP = 13;
} }

View file

@ -19,7 +19,7 @@ class Logger extends \SplFixedArray
{ {
private $bUsed = false; private $bUsed = false;
private $aForbiddenTypes = []; private $iLevel = \LOG_WARNING;
private $aSecretWords = []; private $aSecretWords = [];
@ -37,36 +37,6 @@ class Logger extends \SplFixedArray
\register_shutdown_function(array($this, '__loggerShutDown')); \register_shutdown_function(array($this, '__loggerShutDown'));
} }
/**
* @staticvar \MailSo\Log\Logger $oInstance;
*/
public static function SingletonInstance() : self
{
static $oInstance = null;
if (null === $oInstance)
{
$oInstance = new self;
}
return $oInstance;
}
public static function IsSystemEnabled() : bool
{
return !!(\MailSo\Config::$SystemLogger instanceof Logger);
}
/**
* @param mixed $mData
*/
public static function SystemLog($mData, int $iType = Enumerations\Type::INFO)
{
if (\MailSo\Config::$SystemLogger instanceof Logger)
{
\MailSo\Config::$SystemLogger->WriteMixed($mData, $iType);
}
}
/** /**
* @staticvar string $sCache; * @staticvar string $sCache;
*/ */
@ -114,43 +84,56 @@ class Logger extends \SplFixedArray
return $this->bShowSecrets; return $this->bShowSecrets;
} }
public function AddForbiddenType(int $iType) : self public function SetLevel(int $iLevel) : self
{ {
$this->aForbiddenTypes[$iType] = true; $this->iLevel = $iLevel;
return $this; return $this;
} }
const PHP_TYPES = array(
\E_ERROR => \LOG_ERR,
\E_WARNING => \LOG_WARNING,
\E_PARSE => \LOG_CRIT,
\E_NOTICE => \LOG_NOTICE,
\E_CORE_ERROR => \LOG_ERR,
\E_CORE_WARNING => \LOG_WARNING,
\E_COMPILE_ERROR => \LOG_ERR,
\E_COMPILE_WARNING => \LOG_WARNING,
\E_USER_ERROR => \LOG_ERR,
\E_USER_WARNING => \LOG_WARNING,
\E_USER_NOTICE => \LOG_NOTICE,
\E_STRICT => \LOG_CRIT,
\E_RECOVERABLE_ERROR => \LOG_ERR,
\E_DEPRECATED => \LOG_INFO,
\E_USER_DEPRECATED => \LOG_INFO
);
const PHP_TYPE_POSTFIX = array(
\E_ERROR => '',
\E_WARNING => '',
\E_PARSE => '-PARSE',
\E_NOTICE => '',
\E_CORE_ERROR => '-CORE',
\E_CORE_WARNING => '-CORE',
\E_COMPILE_ERROR => '-COMPILE',
\E_COMPILE_WARNING => '-COMPILE',
\E_USER_ERROR => '-USER',
\E_USER_WARNING => '-USER',
\E_USER_NOTICE => '-USER',
\E_STRICT => '-STRICT',
\E_RECOVERABLE_ERROR => '-RECOVERABLE',
\E_DEPRECATED => '-DEPRECATED',
\E_USER_DEPRECATED => '-USER_DEPRECATED'
);
public function __phpErrorHandler(int $iErrNo, string $sErrStr, string $sErrFile, int $iErrLine) : bool public function __phpErrorHandler(int $iErrNo, string $sErrStr, string $sErrFile, int $iErrLine) : bool
{ {
if (\error_reporting() & $iErrNo) { if (\error_reporting() & $iErrNo) {
$iType = Enumerations\Type::NOTICE_PHP; $this->Write(
switch ($iErrNo) "{$sErrStr} {$sErrFile} [line:{$iErrLine}, code:{$iErrNo}]",
{ static::PHP_TYPES[$iErrNo],
case E_USER_ERROR: 'PHP' . static::PHP_TYPE_POSTFIX[$iErrNo]
$iType = Enumerations\Type::ERROR_PHP; );
break;
case E_USER_WARNING:
$iType = Enumerations\Type::WARNING_PHP;
break;
}
/*
case E_ERROR:
case E_WARNING:
case E_PARSE:
case E_NOTICE:
case E_CORE_ERROR:
case E_CORE_WARNING:
case E_COMPILE_ERROR:
case E_COMPILE_WARNING:
case E_USER_NOTICE:
case E_STRICT:
case E_RECOVERABLE_ERROR:
case E_DEPRECATED:
case E_USER_DEPRECATED:
*/
$this->Write($sErrFile.' [line:'.$iErrLine.', code:'.$iErrNo.']', $iType, 'PHP');
$this->Write('Error: '.$sErrStr, $iType, 'PHP');
} }
/* forward to standard PHP error handler */ /* forward to standard PHP error handler */
return false; return false;
@ -158,31 +141,16 @@ class Logger extends \SplFixedArray
public function __loggerShutDown() : void public function __loggerShutDown() : void
{ {
if ($this->bUsed) if ($this->bUsed) {
{ $this->Write('Memory peak usage: '.\MailSo\Base\Utils::FormatFileSize(\memory_get_peak_usage(true), 2));
$this->Write('Memory peak usage: '.\MailSo\Base\Utils::FormatFileSize(\memory_get_peak_usage(true), 2), $this->Write('Time delta: '.(\microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']));
Enumerations\Type::MEMORY);
$this->Write('Time delta: '.(\microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), Enumerations\Type::TIME_DELTA);
} }
} }
public function WriteEmptyLine() : bool public function Write(string $sDesc, int $iType = \LOG_INFO,
{
$iResult = 1;
foreach ($this as /* @var $oLogger \MailSo\Log\Driver */ $oLogger)
{
$iResult = $oLogger->WriteEmptyLine();
}
return (bool) $iResult;
}
public function Write(string $sDesc, int $iType = Enumerations\Type::INFO,
string $sName = '', bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool string $sName = '', bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool
{ {
if (!empty($this->aForbiddenTypes[$iType])) if ($this->iLevel < $iType) {
{
return true; return true;
} }
@ -206,13 +174,13 @@ class Logger extends \SplFixedArray
/** /**
* @param mixed $oValue * @param mixed $oValue
*/ */
public function WriteDump($oValue, int $iType = Enumerations\Type::INFO, string $sName = '', public function WriteDump($oValue, int $iType = \LOG_INFO, string $sName = '',
bool $bSearchSecretWords = false, bool $bDiplayCrLf = false) : bool bool $bSearchSecretWords = false, bool $bDiplayCrLf = false) : bool
{ {
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
} }
public function WriteException(\Throwable $oException, int $iType = Enumerations\Type::NOTICE, string $sName = '', public function WriteException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '',
bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool
{ {
if ($oException instanceof \Throwable) if ($oException instanceof \Throwable)
@ -230,7 +198,7 @@ class Logger extends \SplFixedArray
return false; return false;
} }
public function WriteExceptionShort(\Throwable $oException, int $iType = Enumerations\Type::NOTICE, string $sName = '', public function WriteExceptionShort(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '',
bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool
{ {
if ($oException instanceof \Throwable) if ($oException instanceof \Throwable)
@ -254,12 +222,12 @@ class Logger extends \SplFixedArray
public function WriteMixed($mData, int $iType = null, string $sName = '', public function WriteMixed($mData, int $iType = null, string $sName = '',
bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool
{ {
$iType = null === $iType ? Enumerations\Type::INFO : $iType; $iType = null === $iType ? \LOG_INFO : $iType;
if (\is_array($mData) || \is_object($mData)) if (\is_array($mData) || \is_object($mData))
{ {
if ($mData instanceof \Throwable) if ($mData instanceof \Throwable)
{ {
$iType = null === $iType ? Enumerations\Type::NOTICE : $iType; $iType = null === $iType ? \LOG_NOTICE : $iType;
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
} }
return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);

View file

@ -126,14 +126,14 @@ abstract class NetClient
if (!\strlen($oSettings->host) || !\MailSo\Base\Validator::PortInt($oSettings->port)) { if (!\strlen($oSettings->host) || !\MailSo\Base\Validator::PortInt($oSettings->port)) {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException, new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
if ($this->IsConnected()) if ($this->IsConnected())
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\SocketAlreadyConnectedException, new Exceptions\SocketAlreadyConnectedException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$sErrorStr = ''; $sErrorStr = '';
@ -155,12 +155,12 @@ abstract class NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('SSL isn\'t supported: ('.\implode(', ', \stream_get_transports()).')'), new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('SSL isn\'t supported: ('.\implode(', ', \stream_get_transports()).')'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->iStartConnectTime = \microtime(true); $this->iStartConnectTime = \microtime(true);
$this->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"', $this->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"',
\MailSo\Log\Enumerations\Type::NOTE); \LOG_INFO);
$aStreamContextSettings = array( $aStreamContextSettings = array(
'ssl' => $oSettings->ssl 'ssl' => $oSettings->ssl
@ -186,7 +186,7 @@ abstract class NetClient
\restore_error_handler(); \restore_error_handler();
$this->writeLog('Connect ('.($this->rConnect ? 'success' : 'failed').')', $this->writeLog('Connect ('.($this->rConnect ? 'success' : 'failed').')',
\MailSo\Log\Enumerations\Type::NOTE); \LOG_INFO);
if (!$this->rConnect) if (!$this->rConnect)
{ {
@ -194,11 +194,10 @@ abstract class NetClient
new Exceptions\SocketCanNotConnectToHostException( new Exceptions\SocketCanNotConnectToHostException(
\MailSo\Base\Locale::ConvertSystemString($sErrorStr), (int) $iErrorNo, \MailSo\Base\Locale::ConvertSystemString($sErrorStr), (int) $iErrorNo,
'Can\'t connect to host "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"' 'Can\'t connect to host "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"'
), \MailSo\Log\Enumerations\Type::NOTICE, true); ), \LOG_NOTICE, true);
} }
$this->writeLog((\microtime(true) - $this->iStartConnectTime).' (raw connection)', $this->writeLog((\microtime(true) - $this->iStartConnectTime).' (raw connection)', \LOG_DEBUG);
\MailSo\Log\Enumerations\Type::TIME);
if ($this->rConnect) if ($this->rConnect)
{ {
@ -228,7 +227,7 @@ abstract class NetClient
if ($bError) { if ($bError) {
$this->writeLogException( $this->writeLogException(
new \MailSo\Net\Exceptions\Exception('Cannot enable STARTTLS.'), new \MailSo\Net\Exceptions\Exception('Cannot enable STARTTLS.'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
} }
@ -247,12 +246,11 @@ abstract class NetClient
$bResult = \fclose($this->rConnect); $bResult = \fclose($this->rConnect);
$this->writeLog('Disconnected from "'.$this->sConnectedHost.':'.$this->iConnectedPort.'" ('. $this->writeLog('Disconnected from "'.$this->sConnectedHost.':'.$this->iConnectedPort.'" ('.
(($bResult) ? 'success' : 'unsuccess').')', \MailSo\Log\Enumerations\Type::NOTE); (($bResult) ? 'success' : 'unsuccess').')', \LOG_INFO);
if ($this->iStartConnectTime) if ($this->iStartConnectTime)
{ {
$this->writeLog((\microtime(true) - $this->iStartConnectTime).' (net session)', $this->writeLog((\microtime(true) - $this->iStartConnectTime).' (net session)', \LOG_DEBUG);
\MailSo\Log\Enumerations\Type::TIME);
$this->iStartConnectTime = 0; $this->iStartConnectTime = 0;
} }
@ -271,7 +269,7 @@ abstract class NetClient
if ($bThrowExceptionOnFalse) { if ($bThrowExceptionOnFalse) {
$this->writeLogException( $this->writeLogException(
new Exceptions\SocketConnectionDoesNotAvailableException, new Exceptions\SocketConnectionDoesNotAvailableException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
return false; return false;
} }
@ -298,9 +296,7 @@ abstract class NetClient
{ {
if ($this->bUnreadBuffer) if ($this->bUnreadBuffer)
{ {
$this->writeLogException( $this->writeLogException(new Exceptions\SocketUnreadBufferException, \LOG_ERR, true);
new Exceptions\SocketUnreadBufferException,
\MailSo\Log\Enumerations\Type::ERROR, true);
} }
$bFake = \strlen($sFakeRaw); $bFake = \strlen($sFakeRaw);
@ -320,18 +316,11 @@ abstract class NetClient
if (false === $mResult) if (false === $mResult)
{ {
$this->IsConnected(true); $this->IsConnected(true);
$this->writeLogException(new Exceptions\SocketWriteException, \LOG_ERR, true);
$this->writeLogException(
new Exceptions\SocketWriteException,
\MailSo\Log\Enumerations\Type::ERROR, true);
} }
else else if ($bWriteToLog)
{ {
if ($bWriteToLog) $this->writeLogWithCrlf('> '.($bFake ? $sFakeRaw : $sRaw), \LOG_INFO);
{
$this->writeLogWithCrlf('> '.($bFake ? $sFakeRaw : $sRaw), //.' ['.$iWriteSize.']',
$bFake ? \MailSo\Log\Enumerations\Type::SECURE : \MailSo\Log\Enumerations\Type::INFO);
}
} }
} }
@ -373,16 +362,16 @@ abstract class NetClient
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\SocketReadTimeoutException, new Exceptions\SocketReadTimeoutException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
else else
{ {
$this->writeLog('Stream Meta: '. $this->writeLog('Stream Meta: '.
\print_r($aSocketStatus, true), \MailSo\Log\Enumerations\Type::ERROR); \print_r($aSocketStatus, true), \LOG_ERR);
$this->writeLogException( $this->writeLogException(
new Exceptions\SocketReadException, new Exceptions\SocketReadException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
} }
else else
@ -394,25 +383,25 @@ abstract class NetClient
if ($iLimit < $iReadedLen) if ($iLimit < $iReadedLen)
{ {
$this->writeLogWithCrlf('[cutted:'.$iReadedLen.'] < '.\substr($this->sResponseBuffer, 0, $iLimit).'...', $this->writeLogWithCrlf('[cutted:'.$iReadedLen.'] < '.\substr($this->sResponseBuffer, 0, $iLimit).'...',
\MailSo\Log\Enumerations\Type::INFO); \LOG_INFO);
} }
else else
{ {
$this->writeLogWithCrlf('< '.$this->sResponseBuffer, //.' ['.$iReadedLen.']', $this->writeLogWithCrlf('< '.$this->sResponseBuffer, //.' ['.$iReadedLen.']',
\MailSo\Log\Enumerations\Type::INFO); \LOG_INFO);
} }
} }
else else
{ {
$this->writeLog('Received '.$iReadedLen.'/'.$iReadLen.' bytes.', $this->writeLog('Received '.$iReadedLen.'/'.$iReadLen.' bytes.',
\MailSo\Log\Enumerations\Type::INFO); \LOG_INFO);
} }
} }
} }
abstract function getLogName() : string; abstract function getLogName() : string;
protected function writeLog(string $sDesc, int $iDescType = \MailSo\Log\Enumerations\Type::INFO, bool $bDiplayCrLf = false) : void protected function writeLog(string $sDesc, int $iDescType = \LOG_INFO, bool $bDiplayCrLf = false) : void
{ {
if ($this->oLogger) if ($this->oLogger)
{ {
@ -420,13 +409,13 @@ abstract class NetClient
} }
} }
protected function writeLogWithCrlf(string $sDesc, int $iDescType = \MailSo\Log\Enumerations\Type::INFO) : void protected function writeLogWithCrlf(string $sDesc, int $iDescType = \LOG_INFO) : void
{ {
$this->writeLog($sDesc, $iDescType, true); $this->writeLog($sDesc, $iDescType, true);
} }
protected function writeLogException(\Throwable $oException, protected function writeLogException(\Throwable $oException,
int $iDescType = \MailSo\Log\Enumerations\Type::NOTICE, bool $bThrowException = false) : void int $iDescType = \LOG_NOTICE, bool $bThrowException = false) : void
{ {
if ($this->oLogger) if ($this->oLogger)
{ {

View file

@ -83,7 +83,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'), new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
} }
@ -101,7 +101,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException, new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
if ($this->IsSupported('SASL')) if ($this->IsSupported('SASL'))
@ -176,21 +176,21 @@ class ManageSieveClient extends \MailSo\Net\NetClient
$this->writeLogException( $this->writeLogException(
new \MailSo\Sieve\Exceptions\LoginBadCredentialsException( new \MailSo\Sieve\Exceptions\LoginBadCredentialsException(
$oException->GetResponses(), '', 0, $oException), $oException->GetResponses(), '', 0, $oException),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
if (!$bAuth) if (!$bAuth)
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Sieve\Exceptions\LoginBadMethodException, new \MailSo\Sieve\Exceptions\LoginBadMethodException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
} }
else else
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Sieve\Exceptions\LoginException, new \MailSo\Sieve\Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->bIsLoggined = true; $this->bIsLoggined = true;
@ -449,7 +449,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException, new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->IsConnected(true); $this->IsConnected(true);
@ -530,7 +530,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Sieve\Exceptions\NegativeResponseException($aResponse), new \MailSo\Sieve\Exceptions\NegativeResponseException($aResponse),
\MailSo\Log\Enumerations\Type::WARNING, true); \LOG_WARNING, true);
} }
} }

View file

@ -134,7 +134,7 @@ class SmtpClient extends \MailSo\Net\NetClient
\trigger_error("SMTP {$this->GetConnectedHost()} no supported AUTH options. Disable login" . ($this->IsSupported('STARTTLS') ? ' or try with STARTTLS' : '')); \trigger_error("SMTP {$this->GetConnectedHost()} no supported AUTH options. Disable login" . ($this->IsSupported('STARTTLS') ? ' or try with STARTTLS' : ''));
$this->writeLogException( $this->writeLogException(
new \MailSo\Smtp\Exceptions\LoginBadMethodException, new \MailSo\Smtp\Exceptions\LoginBadMethodException,
\MailSo\Log\Enumerations\Type::NOTICE, true); \LOG_NOTICE, true);
} }
$SASL = \SnappyMail\SASL::factory($type); $SASL = \SnappyMail\SASL::factory($type);
@ -150,7 +150,7 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->writeLogException( $this->writeLogException(
new \MailSo\Smtp\Exceptions\LoginBadMethodException( new \MailSo\Smtp\Exceptions\LoginBadMethodException(
$oException->GetResponses(), $oException->getMessage(), 0, $oException), $oException->GetResponses(), $oException->getMessage(), 0, $oException),
\MailSo\Log\Enumerations\Type::NOTICE, true); \LOG_NOTICE, true);
} }
try try
@ -178,7 +178,7 @@ class SmtpClient extends \MailSo\Net\NetClient
if (empty($sResult)) { if (empty($sResult)) {
$this->writeLogException( $this->writeLogException(
new \MailSo\Smtp\Exceptions\NegativeResponseException, new \MailSo\Smtp\Exceptions\NegativeResponseException,
\MailSo\Log\Enumerations\Type::NOTICE, true \LOG_NOTICE, true
); );
} }
$this->sendRequestWithCheck($SASL->authenticate($sLogin, $sPassword, $sResult), 235, '', true); $this->sendRequestWithCheck($SASL->authenticate($sLogin, $sPassword, $sResult), 235, '', true);
@ -190,7 +190,7 @@ class SmtpClient extends \MailSo\Net\NetClient
$this->writeLogException( $this->writeLogException(
new \MailSo\Smtp\Exceptions\LoginBadCredentialsException( new \MailSo\Smtp\Exceptions\LoginBadCredentialsException(
$oException->GetResponses(), $oException->getMessage(), 0, $oException), $oException->GetResponses(), $oException->getMessage(), 0, $oException),
\MailSo\Log\Enumerations\Type::NOTICE, true); \LOG_NOTICE, true);
} }
return $this; return $this;
@ -236,7 +236,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\RuntimeException('No sender reverse path has been supplied'), new Exceptions\RuntimeException('No sender reverse path has been supplied'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$sTo = \MailSo\Base\Utils::IdnToAscii( $sTo = \MailSo\Base\Utils::IdnToAscii(
@ -305,12 +305,12 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\RuntimeException('No recipient forward path has been supplied'), new Exceptions\RuntimeException('No recipient forward path has been supplied'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->sendRequestWithCheck('DATA', 354); $this->sendRequestWithCheck('DATA', 354);
$this->writeLog('Message data.', \MailSo\Log\Enumerations\Type::NOTE); $this->writeLog('Message data.', \LOG_INFO);
$this->bRunningCallback = true; $this->bRunningCallback = true;
@ -333,7 +333,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\RuntimeException('Cannot read input resource'), new Exceptions\RuntimeException('Cannot read input resource'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
break; break;
@ -411,7 +411,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\RuntimeException('Cannot issue EHLO/HELO to existing session'), new Exceptions\RuntimeException('Cannot issue EHLO/HELO to existing session'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->ehloOrHelo($sEhloHost); $this->ehloOrHelo($sEhloHost);
@ -427,7 +427,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'), new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'),
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->bHelo = true; $this->bHelo = true;
@ -443,7 +443,7 @@ class SmtpClient extends \MailSo\Net\NetClient
{ {
$this->writeLogException( $this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException, new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true); \LOG_ERR, true);
} }
$this->IsConnected(true); $this->IsConnected(true);
@ -568,7 +568,7 @@ class SmtpClient extends \MailSo\Net\NetClient
new Exceptions\NegativeResponseException($this->aResults, new Exceptions\NegativeResponseException($this->aResults,
('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim( ('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim(
(\count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : ''). (\count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
$this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true); $this->sResponseBuffer)), \LOG_ERR, true);
} }
} }
else else
@ -577,7 +577,7 @@ class SmtpClient extends \MailSo\Net\NetClient
new Exceptions\ResponseException($this->aResults, new Exceptions\ResponseException($this->aResults,
('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim( ('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim(
(\count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : ''). (\count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
$this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true); $this->sResponseBuffer)), \LOG_ERR, true);
} }
$this->aResults[] = $this->sResponseBuffer; $this->aResults[] = $this->sResponseBuffer;

View file

@ -122,76 +122,31 @@ class Actions
$this->oConfig = API::Config(); $this->oConfig = API::Config();
$this->oLogger = API::Logger(); $this->oLogger = API::Logger();
if ($this->oConfig->Get('logs', 'enable', false)) { if ($this->oConfig->Get('logs', 'enable', false) || $this->oConfig->Get('debug', 'enable', false)) {
$sSessionFilter = (string)$this->oConfig->Get('logs', 'session_filter', '');
if (!empty($sSessionFilter)) {
$aSessionParts = \explode(':', $sSessionFilter, 2);
if (empty($aSessionParts[0]) || empty($aSessionParts[1]) ||
(string)$aSessionParts[1] !== (string)Utils::GetCookie($aSessionParts[0], '')) {
return $this->oLogger;
}
}
$sTimeZone = $this->oConfig->Get('logs', 'time_zone', 'UTC');
$this->oLogger->SetShowSecrets(!$this->oConfig->Get('logs', 'hide_passwords', true));
$sLogFileName = $this->oConfig->Get('logs', 'filename', '');
$oDriver = null; $oDriver = null;
$sLogFileName = $this->oConfig->Get('logs', 'filename', '');
if ('syslog' === $sLogFileName) { if ('syslog' === $sLogFileName) {
$oDriver = new \MailSo\Log\Drivers\Syslog(); $oDriver = new \MailSo\Log\Drivers\Syslog();
} else { } else {
$sLogFileFullPath = \APP_PRIVATE_DATA . 'logs/' . $this->compileLogFileName($sLogFileName); $sLogFileFullPath = \APP_PRIVATE_DATA . 'logs/' . $this->compileLogFileName($sLogFileName);
$sLogFileDir = \dirname($sLogFileFullPath);
if (!\is_dir($sLogFileDir)) {
\mkdir($sLogFileDir, 0755, true);
}
$oDriver = new \MailSo\Log\Drivers\File($sLogFileFullPath); $oDriver = new \MailSo\Log\Drivers\File($sLogFileFullPath);
} }
$this->oLogger->append($oDriver $this->oLogger->append($oDriver
->WriteOnErrorOnly($this->oConfig->Get('logs', 'write_on_error_only', false)) ->SetTimeZone($this->oConfig->Get('logs', 'time_zone', 'UTC'))
->WriteOnPhpErrorOnly($this->oConfig->Get('logs', 'write_on_php_error_only', false))
->WriteOnTimeoutOnly($this->oConfig->Get('logs', 'write_on_timeout_only', 0))
->SetTimeZone($sTimeZone)
); );
if (!$this->oConfig->Get('debug', 'enable', false)) {
$this->oLogger->AddForbiddenType(\MailSo\Log\Enumerations\Type::TIME);
}
$level = \max(3, \RainLoop\Api::Config()->Get('logs', 'level', \LOG_WARNING)) - 3;
$mailso = [
\MailSo\Log\Enumerations\Type::ERROR,
\MailSo\Log\Enumerations\Type::WARNING,
\MailSo\Log\Enumerations\Type::NOTICE,
\MailSo\Log\Enumerations\Type::INFO,
\MailSo\Log\Enumerations\Type::DEBUG
];
while (4 > $level++) {
$this->oLogger->AddForbiddenType($mailso[$level]);
}
$this->oLogger->WriteEmptyLine();
$oHttp = $this->Http(); $oHttp = $this->Http();
$this->oLogger->Write('[DATE:' . (new \DateTime('now', new \DateTimeZone($sTimeZone)))->format('Y-m-d ') .
$sTimeZone .
'][SM:' . APP_VERSION . '][IP:' .
$oHttp->GetClientIp($this->oConfig->Get('labs', 'http_client_ip_check_proxy', false)) . '][PID:' .
(\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown') . '][' .
$oHttp->GetServer('SERVER_SOFTWARE', '~') . '][' .
(\MailSo\Base\Utils::FunctionExistsAndEnabled('php_sapi_name') ? \php_sapi_name() : '~') . '][Streams:' . \implode(',', \stream_get_transports()) . ']'
);
$this->oLogger->Write( $this->oLogger->Write(
'[' . $oHttp->GetMethod() . '] ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false, false) . $oHttp->GetServer('REQUEST_URI', ''), '[SM:' . APP_VERSION . '][IP:'
\MailSo\Log\Enumerations\Type::NOTE, 'REQUEST'); . $oHttp->GetClientIp($this->oConfig->Get('labs', 'http_client_ip_check_proxy', false))
. '][PID:' . (\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown')
. '][' . $oHttp->GetServer('SERVER_SOFTWARE', '~')
. '][' . (\MailSo\Base\Utils::FunctionExistsAndEnabled('php_sapi_name') ? \php_sapi_name() : '~')
. '][Streams:' . \implode(',', \stream_get_transports())
. '][' . $oHttp->GetMethod() . ' ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false, false) . $oHttp->GetServer('REQUEST_URI', '') . ']'
);
} }
$this->oPlugins = new Plugins\Manager($this); $this->oPlugins = new Plugins\Manager($this);
@ -407,7 +362,7 @@ class Actions
{ {
$sFileName = \trim($sFileName); $sFileName = \trim($sFileName);
if (0 !== \strlen($sFileName)) { if (\strlen($sFileName)) {
$sFileName = $this->compileLogParams($sFileName); $sFileName = $this->compileLogParams($sFileName);
$sFileName = \preg_replace('/[\/]+/', '/', \preg_replace('/[.]+/', '.', $sFileName)); $sFileName = \preg_replace('/[\/]+/', '/', \preg_replace('/[.]+/', '.', $sFileName));
@ -415,7 +370,7 @@ class Actions
} }
if (!\strlen($sFileName)) { if (!\strlen($sFileName)) {
$sFileName = 'rainloop-log.txt'; $sFileName = 'snappymail-log.txt';
} }
return $sFileName; return $sFileName;
@ -602,34 +557,26 @@ class Actions
public function LoggerAuth(): \MailSo\Log\Logger public function LoggerAuth(): \MailSo\Log\Logger
{ {
if (null === $this->oLoggerAuth) { if (!$this->oLoggerAuth) {
$this->oLoggerAuth = new \MailSo\Log\Logger(false); $this->oLoggerAuth = new \MailSo\Log\Logger(false);
if ($this->oConfig->Get('logs', 'auth_logging', false)) { if ($this->oConfig->Get('logs', 'auth_logging', false)) {
// $this->oLoggerAuth->SetLevel(\LOG_WARNING);
$sAuthLogFileFullPath = \APP_PRIVATE_DATA . 'logs/' . $this->compileLogFileName( $sAuthLogFileFullPath = \APP_PRIVATE_DATA . 'logs/' . $this->compileLogFileName(
$this->oConfig->Get('logs', 'auth_logging_filename', '')); $this->oConfig->Get('logs', 'auth_logging_filename', ''));
$sLogFileDir = \dirname($sAuthLogFileFullPath); $sLogFileDir = \dirname($sAuthLogFileFullPath);
if (!\is_dir($sLogFileDir)) {
if (!is_dir($sLogFileDir)) { \mkdir($sLogFileDir, 0755, true);
mkdir($sLogFileDir, 0755, true);
} }
$this->oLoggerAuth $this->oLoggerAuth->append(
->AddForbiddenType(\MailSo\Log\Enumerations\Type::MEMORY) (new \MailSo\Log\Drivers\File($sAuthLogFileFullPath))
->AddForbiddenType(\MailSo\Log\Enumerations\Type::TIME) ->DisableTimePrefix()
->AddForbiddenType(\MailSo\Log\Enumerations\Type::TIME_DELTA); ->DisableGuidPrefix()
->DisableTypedPrefix()
$oDriver = new \MailSo\Log\Drivers\File($sAuthLogFileFullPath); );
$oDriver->DisableTimePrefix();
$oDriver->DisableGuidPrefix();
$oDriver->DisableTypedPrefix();
$this->oLoggerAuth->append($oDriver);
} }
} }
return $this->oLoggerAuth; return $this->oLoggerAuth;
} }

View file

@ -201,7 +201,7 @@ trait Messages
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
} }
} }
@ -266,7 +266,7 @@ trait Messages
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
} }
} }
@ -824,12 +824,9 @@ trait Messages
)); ));
} }
if ($this->Config()->Get('debug', 'enable', false)) $this->Logger()->WriteDump(array(
{ $sMailTo, $sMailSubject, $sMailBody, $sMailHeaders
$this->Logger()->WriteDump(array( ), \LOG_DEBUG);
$sMailTo, $sMailSubject, $sMailBody, $sMailHeaders
));
}
$bR = $this->Config()->Get('labs', 'mail_func_additional_parameters', false) ? $bR = $this->Config()->Get('labs', 'mail_func_additional_parameters', false) ?
\mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders, '-f'.$oFrom->GetEmail()) : \mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders, '-f'.$oFrom->GetEmail()) :

View file

@ -33,11 +33,11 @@ trait UserAuth
} }
if (!\str_contains($sEmail, '@')) { if (!\str_contains($sEmail, '@')) {
$this->Logger()->Write('The email address "' . $sEmail . '" is not complete', \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); $this->Logger()->Write('The email address "' . $sEmail . '" is not complete', \LOG_INFO, 'LOGIN');
if ($this->Config()->Get('login', 'determine_user_domain', false)) { if ($this->Config()->Get('login', 'determine_user_domain', false)) {
$sUserHost = \trim($this->Http()->GetHost(false, true, true)); $sUserHost = \trim($this->Http()->GetHost(false, true, true));
$this->Logger()->Write('Determined user domain: ' . $sUserHost, \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); $this->Logger()->Write('Determined user domain: ' . $sUserHost, \LOG_INFO, 'LOGIN');
$bAdded = false; $bAdded = false;
@ -52,12 +52,12 @@ trait UserAuth
if ($oDomain) { if ($oDomain) {
$bAdded = true; $bAdded = true;
$this->Logger()->Write('Check "' . $sLine . '": OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')', $this->Logger()->Write('Check "' . $sLine . '": OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')',
\MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); \LOG_INFO, 'LOGIN');
$sEmail .= '@' . $sLine; $sEmail .= '@' . $sLine;
break; break;
} else { } else {
$this->Logger()->Write('Check "' . $sLine . '": NO', \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); $this->Logger()->Write('Check "' . $sLine . '": NO', \LOG_INFO, 'LOGIN');
} }
\array_shift($aDomainParts); \array_shift($aDomainParts);
@ -70,23 +70,23 @@ trait UserAuth
if ($oDomain && $oDomain) { if ($oDomain && $oDomain) {
$bAdded = true; $bAdded = true;
$this->Logger()->Write('Check "' . $sLine . '" with wildcard: OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')', $this->Logger()->Write('Check "' . $sLine . '" with wildcard: OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')',
\MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); \LOG_INFO, 'LOGIN');
$sEmail .= '@' . $sLine; $sEmail .= '@' . $sLine;
} else { } else {
$this->Logger()->Write('Check "' . $sLine . '" with wildcard: NO', \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); $this->Logger()->Write('Check "' . $sLine . '" with wildcard: NO', \LOG_INFO, 'LOGIN');
} }
} }
if (!$bAdded) { if (!$bAdded) {
$this->Logger()->Write('Domain was not found!', \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); $this->Logger()->Write('Domain was not found!', \LOG_INFO, 'LOGIN');
} }
} }
$sDefDomain = \trim($this->Config()->Get('login', 'default_domain', '')); $sDefDomain = \trim($this->Config()->Get('login', 'default_domain', ''));
if (!\str_contains($sEmail, '@') && \strlen($sDefDomain)) { if (!\str_contains($sEmail, '@') && \strlen($sDefDomain)) {
$this->Logger()->Write('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')', $this->Logger()->Write('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')',
\MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); \LOG_INFO, 'LOGIN');
$sEmail .= '@' . $sDefDomain; $sEmail .= '@' . $sDefDomain;
} }

View file

@ -309,7 +309,7 @@ class ActionsAdmin extends Actions
} }
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
$sImapErrorDesc = $oException->getSocketMessage(); $sImapErrorDesc = $oException->getSocketMessage();
if (empty($sImapErrorDesc)) if (empty($sImapErrorDesc))
{ {
@ -318,7 +318,7 @@ class ActionsAdmin extends Actions
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
$sImapErrorDesc = $oException->getMessage(); $sImapErrorDesc = $oException->getMessage();
} }
@ -350,7 +350,7 @@ class ActionsAdmin extends Actions
} }
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
$sSmtpErrorDesc = $oException->getSocketMessage(); $sSmtpErrorDesc = $oException->getSocketMessage();
if (empty($sSmtpErrorDesc)) if (empty($sSmtpErrorDesc))
{ {
@ -359,7 +359,7 @@ class ActionsAdmin extends Actions
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
$sSmtpErrorDesc = $oException->getMessage(); $sSmtpErrorDesc = $oException->getMessage();
} }
} }
@ -384,7 +384,7 @@ class ActionsAdmin extends Actions
} }
catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
$sSieveErrorDesc = $oException->getSocketMessage(); $sSieveErrorDesc = $oException->getSocketMessage();
if (empty($sSieveErrorDesc)) if (empty($sSieveErrorDesc))
{ {
@ -393,7 +393,7 @@ class ActionsAdmin extends Actions
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
$sSieveErrorDesc = $oException->getMessage(); $sSieveErrorDesc = $oException->getMessage();
} }
} }
@ -688,7 +688,7 @@ class ActionsAdmin extends Actions
if (!$this->Cacher(null, true)->Set(KeyPathHelper::SessionAdminKey($sRand), \time())) if (!$this->Cacher(null, true)->Set(KeyPathHelper::SessionAdminKey($sRand), \time()))
{ {
$this->oLogger->Write('Cannot store an admin token', $this->oLogger->Write('Cannot store an admin token',
\MailSo\Log\Enumerations\Type::WARNING); \LOG_WARNING);
return ''; return '';
} }

View file

@ -36,9 +36,10 @@ abstract class Api
\usleep(10000); \usleep(10000);
$oConfig->Load(); $oConfig->Load();
} }
// \ini_set('display_errors', 0);
if ($oConfig->Get('debug', 'enable', false)) { if ($oConfig->Get('debug', 'enable', false)) {
\error_reporting(E_ALL); \error_reporting(E_ALL);
\ini_set('display_errors', 1); // \ini_set('display_errors', 1);
\ini_set('log_errors', 1); \ini_set('log_errors', 1);
} }
} }
@ -47,7 +48,19 @@ abstract class Api
public static function Logger() : \MailSo\Log\Logger public static function Logger() : \MailSo\Log\Logger
{ {
return \MailSo\Log\Logger::SingletonInstance(); static $oLogger = null;
if (!$oLogger) {
$oConfig = static::Config();
$oLogger = new \MailSo\Log\Logger;
if ($oConfig->Get('debug', 'enable', false)) {
$oLogger->SetShowSecrets(!$oConfig->Get('logs', 'hide_passwords', true));
$oLogger->SetLevel(\LOG_DEBUG);
} else if ($oConfig->Get('logs', 'enable', false)) {
$oLogger->SetShowSecrets(!$oConfig->Get('logs', 'hide_passwords', true));
$oLogger->SetLevel(\max(3, \RainLoop\Api::Config()->Get('logs', 'level', \LOG_WARNING)));
}
}
return $oLogger;
} }
protected static function SetupDefaultMailSoConfig() : void protected static function SetupDefaultMailSoConfig() : void
@ -78,8 +91,6 @@ abstract class Api
\MailSo\Config::$BoundaryPrefix = \MailSo\Config::$BoundaryPrefix =
\trim(static::Config()->Get('labs', 'boundary_prefix', '')); \trim(static::Config()->Get('labs', 'boundary_prefix', ''));
\MailSo\Config::$SystemLogger = static::Logger();
$sSslCafile = static::Config()->Get('ssl', 'cafile', ''); $sSslCafile = static::Config()->Get('ssl', 'cafile', '');
$sSslCapath = static::Config()->Get('ssl', 'capath', ''); $sSslCapath = static::Config()->Get('ssl', 'capath', '');

View file

@ -233,7 +233,7 @@ abstract class PdoAbstract
{ {
if ($this->oLogger) if ($this->oLogger)
{ {
$this->oLogger->WriteMixed($mData, \MailSo\Log\Enumerations\Type::INFO, 'SQL'); $this->oLogger->WriteMixed($mData, \LOG_INFO, 'SQL');
} }
} }

View file

@ -267,15 +267,10 @@ Values:
6 = Informational 6 = Informational
7 = Debug'), 7 = Debug'),
'write_on_error_only' => array(false, 'Logs entire request only if error occured (php required)'),
'write_on_php_error_only' => array(false, 'Logs entire request only if php error occured'),
'write_on_timeout_only' => array(0, 'Logs entire request only if request timeout (in seconds) occured.'),
'hide_passwords' => array(true, 'Required for development purposes only. 'hide_passwords' => array(true, 'Required for development purposes only.
Disabling this option is not recommended.'), Disabling this option is not recommended.'),
'time_zone' => array('UTC'), 'time_zone' => array('UTC'),
'session_filter' => array(''),
'filename' => array('log-{date:Y-m-d}.txt', 'filename' => array('log-{date:Y-m-d}.txt',
'Log filename. 'Log filename.

View file

@ -44,7 +44,6 @@ class Manager
$oPlugin = $this->CreatePluginByName($sName); $oPlugin = $this->CreatePluginByName($sName);
if ($oPlugin) { if ($oPlugin) {
$oPlugin->Init(); $oPlugin->Init();
$this->aPlugins[] = $oPlugin; $this->aPlugins[] = $oPlugin;
} else { } else {
unset($aList[$i]); unset($aList[$i]);
@ -84,6 +83,9 @@ class Manager
->SetPluginManager($this) ->SetPluginManager($this)
->SetPluginConfig(new \RainLoop\Config\Plugin($sName, $oPlugin->ConfigMap(true))) ->SetPluginConfig(new \RainLoop\Config\Plugin($sName, $oPlugin->ConfigMap(true)))
; ;
if (\method_exists($oPlugin, 'SetLogger')) {
$oPlugin->SetLogger($this->oLogger);
}
} }
return $oPlugin; return $oPlugin;
@ -119,7 +121,7 @@ class Manager
else else
{ {
$this->oActions->Logger()->Write('Cannot get installed plugins from '.APP_PLUGINS_PATH, $this->oActions->Logger()->Write('Cannot get installed plugins from '.APP_PLUGINS_PATH,
\MailSo\Log\Enumerations\Type::ERROR); \LOG_ERR);
} }
return $aList; return $aList;
@ -316,7 +318,7 @@ class Manager
{ {
if ($bLogHook) if ($bLogHook)
{ {
$this->WriteLog('Hook: '.$sHookName, \MailSo\Log\Enumerations\Type::NOTE); $this->WriteLog('Hook: '.$sHookName, \LOG_INFO);
} }
foreach ($this->aHooks[$sHookName] as $mCallback) foreach ($this->aHooks[$sHookName] as $mCallback)
@ -525,7 +527,7 @@ class Manager
return $this; return $this;
} }
public function WriteLog(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO) : void public function WriteLog(string $sDesc, int $iType = \LOG_INFO) : void
{ {
if ($this->oLogger) if ($this->oLogger)
{ {
@ -533,7 +535,7 @@ class Manager
} }
} }
public function WriteException(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO) : void public function WriteException(string $sDesc, int $iType = \LOG_INFO) : void
{ {
if ($this->oLogger) if ($this->oLogger)
{ {

View file

@ -28,7 +28,7 @@ trait CardDAV
$aResponse = null; $aResponse = null;
try try
{ {
$this->oLogger->Write('PROPFIND '.$sPath, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); $this->oLogger->Write('PROPFIND '.$sPath, \LOG_INFO, 'DAV');
$aResponse = $oClient->propFind($sPath, array( $aResponse = $oClient->propFind($sPath, array(
'{DAV:}getlastmodified', '{DAV:}getlastmodified',
@ -100,11 +100,11 @@ trait CardDAV
\MailSo\Base\Utils::ResetTimeLimit(); \MailSo\Base\Utils::ResetTimeLimit();
$this->oLogger->Write($sCmd.' '.$sUrl.(('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData ? ' ('.\strlen($mData).')' : ''), $this->oLogger->Write($sCmd.' '.$sUrl.(('PUT' === $sCmd || 'POST' === $sCmd) && null !== $mData ? ' ('.\strlen($mData).')' : ''),
\MailSo\Log\Enumerations\Type::INFO, 'DAV'); \LOG_INFO, 'DAV');
// if ('PUT' === $sCmd || 'POST' === $sCmd) // if ('PUT' === $sCmd || 'POST' === $sCmd)
// { // {
// $this->oLogger->Write($mData, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); // $this->oLogger->Write($mData, \LOG_INFO, 'DAV');
// } // }
try try
@ -122,7 +122,7 @@ trait CardDAV
// if ('GET' === $sCmd) // if ('GET' === $sCmd)
// { // {
// $this->oLogger->WriteDump($aResponse, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); // $this->oLogger->WriteDump($aResponse, \LOG_INFO, 'DAV');
// } // }
} }
catch (\Throwable $oException) catch (\Throwable $oException)
@ -139,7 +139,7 @@ trait CardDAV
try try
{ {
$this->oLogger->Write('PROPFIND '.$sPath, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); $this->oLogger->Write('PROPFIND '.$sPath, \LOG_INFO, 'DAV');
$aResponse = $oClient->propFind($sPath, array( $aResponse = $oClient->propFind($sPath, array(
'{DAV:}current-user-principal', '{DAV:}current-user-principal',
@ -336,7 +336,7 @@ trait CardDAV
return false; return false;
} }
$this->oLogger->Write('PROPFIND '.$sPath, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); $this->oLogger->Write('PROPFIND '.$sPath, \LOG_INFO, 'DAV');
$aResponse = null; $aResponse = null;
try try
@ -412,7 +412,7 @@ trait CardDAV
$oClient->__UrlPath__ = $aUrl['path']; $oClient->__UrlPath__ = $aUrl['path'];
$this->oLogger->Write('DavClient: User: '.$aSettings['userName'].', Url: '.$sUrl, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); $this->oLogger->Write('DavClient: User: '.$aSettings['userName'].', Url: '.$sUrl, \LOG_INFO, 'DAV');
return $oClient; return $oClient;
} }

View file

@ -117,7 +117,7 @@ class ServiceActions
$sMethodName = 'Do'.$sAction; $sMethodName = 'Do'.$sAction;
$this->Logger()->Write('Action: '.$sMethodName, \MailSo\Log\Enumerations\Type::NOTE, 'JSON'); $this->Logger()->Write('Action: '.$sMethodName, \LOG_INFO, 'JSON');
$aPost = $_POST ?? null; $aPost = $_POST ?? null;
if ($aPost) if ($aPost)
@ -139,7 +139,7 @@ class ServiceActions
} }
*/ */
$this->Logger()->Write(\MailSo\Base\Utils::Php2js($aPost, $this->Logger()), $this->Logger()->Write(\MailSo\Base\Utils::Php2js($aPost, $this->Logger()),
\MailSo\Log\Enumerations\Type::INFO, 'POST', true); \LOG_INFO, 'POST', true);
} }
else if (3 < \count($this->aPaths) && $this->oHttp->IsGet()) else if (3 < \count($this->aPaths) && $this->oHttp->IsGet())
{ {
@ -198,17 +198,17 @@ class ServiceActions
{ {
if (\strlen($sObResult)) if (\strlen($sObResult))
{ {
$this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); $this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA');
} }
if ($oException) if ($oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
} }
$iLimit = (int) $this->Config()->Get('labs', 'log_ajax_response_write_limit', 0); $iLimit = (int) $this->Config()->Get('labs', 'log_ajax_response_write_limit', 0);
$this->Logger()->Write(0 < $iLimit && $iLimit < \strlen($sResult) $this->Logger()->Write(0 < $iLimit && $iLimit < \strlen($sResult)
? \substr($sResult, 0, $iLimit).'...' : $sResult, \MailSo\Log\Enumerations\Type::INFO, 'JSON'); ? \substr($sResult, 0, $iLimit).'...' : $sResult, \LOG_INFO, 'JSON');
} }
return $sResult; return $sResult;
@ -239,15 +239,15 @@ class ServiceActions
$sObResult = \ob_get_clean(); $sObResult = \ob_get_clean();
if (\strlen($sObResult)) if (\strlen($sObResult))
{ {
$this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); $this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA');
} }
if ($oException) if ($oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->WriteException($oException, \LOG_ERR);
} }
$this->Logger()->Write($sResult, \MailSo\Log\Enumerations\Type::INFO, 'APPEND'); $this->Logger()->Write($sResult, \LOG_INFO, 'APPEND');
return $sResult; return $sResult;
} }
@ -322,10 +322,10 @@ class ServiceActions
$sObResult = \ob_get_clean(); $sObResult = \ob_get_clean();
if (\strlen($sObResult)) if (\strlen($sObResult))
{ {
$this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); $this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA');
} }
$this->Logger()->Write($sResult, \MailSo\Log\Enumerations\Type::INFO, 'UPLOAD'); $this->Logger()->Write($sResult, \LOG_INFO, 'UPLOAD');
return $sResult; return $sResult;
} }
@ -443,13 +443,13 @@ class ServiceActions
if (\strlen($sRawError)) if (\strlen($sRawError))
{ {
$this->Logger()->Write($sRawError, \MailSo\Log\Enumerations\Type::ERROR); $this->Logger()->Write($sRawError, \LOG_ERR);
$this->Logger()->WriteDump($this->aPaths, \MailSo\Log\Enumerations\Type::ERROR, 'PATHS'); $this->Logger()->WriteDump($this->aPaths, \LOG_ERR, 'PATHS');
} }
if ($oException) if ($oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR, 'RAW'); $this->Logger()->WriteException($oException, \LOG_ERR, 'RAW');
} }
return $sResult; return $sResult;
@ -583,7 +583,7 @@ class ServiceActions
} }
catch (\Throwable $oException) catch (\Throwable $oException)
{ {
$this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR, 'LESS'); $this->Logger()->WriteException($oException, \LOG_ERR, 'LESS');
} }
} }
@ -652,7 +652,7 @@ class ServiceActions
$this->oHttp->ServerNoCache(); $this->oHttp->ServerNoCache();
\header('Content-Type: text/plain; charset=utf-8'); \header('Content-Type: text/plain; charset=utf-8');
$this->oActions->Logger()->Write('Pong', \MailSo\Log\Enumerations\Type::INFO, 'PING'); $this->oActions->Logger()->Write('Pong', \LOG_INFO, 'PING');
return 'Pong'; return 'Pong';
} }
@ -841,7 +841,7 @@ class ServiceActions
.\json_encode($this->oActions->AppData($bAdmin)) .\json_encode($this->oActions->AppData($bAdmin))
.');'; .');';
$this->Logger()->Write($sResult, \MailSo\Log\Enumerations\Type::INFO, 'APPDATA'); $this->Logger()->Write($sResult, \LOG_INFO, 'APPDATA');
return $sResult; return $sResult;
} }

View file

@ -2,8 +2,6 @@
namespace SnappyMail; namespace SnappyMail;
use MailSo\Log\Enumerations\Type;
abstract class Log abstract class Log
{ {
// Same as RFC 5424 section 6.2.1 decimal Severity level indicator // Same as RFC 5424 section 6.2.1 decimal Severity level indicator
@ -35,44 +33,32 @@ abstract class Log
\LOG_NOTICE => 'NOTICE', \LOG_NOTICE => 'NOTICE',
\LOG_INFO => 'INFO', \LOG_INFO => 'INFO',
\LOG_DEBUG => 'DEBUG', \LOG_DEBUG => 'DEBUG',
],
$mailso = [
\LOG_EMERG => Type::ERROR,
\LOG_ALERT => Type::ERROR,
\LOG_CRIT => Type::ERROR,
\LOG_ERR => Type::ERROR,
\LOG_WARNING => Type::WARNING,
\LOG_NOTICE => Type::NOTICE,
\LOG_INFO => Type::INFO,
\LOG_DEBUG => Type::DEBUG
]; ];
protected static function log(int $level, string $prefix, string $msg) protected static function log(int $level, string $prefix, string $msg)
{ {
\RainLoop\Api::Logger()->Write($msg, $level, $prefix);
/*
static $log_level; static $log_level;
// Default to level 4, 0 = LOG_EMERG, 7 = LOG_DEBUG // Default to level 4, 0 = LOG_EMERG, 7 = LOG_DEBUG
if (!$log_level) { if (!$log_level) {
$log_level = \max(3, \RainLoop\Api::Config()->Get('logs', 'level', \LOG_WARNING)); $log_level = \max(3, \RainLoop\Api::Config()->Get('logs', 'level', \LOG_WARNING));
} }
if ($level <= $log_level) { if ($level <= $log_level) {
\RainLoop\Api::Logger()->Write(
$msg,
static::$mailso[$level],
$prefix
);
/*
if (\RainLoop\Api::Config()->Get('logs', 'syslog') && \openlog('snappymail', \LOG_ODELAY, \LOG_USER)) { if (\RainLoop\Api::Config()->Get('logs', 'syslog') && \openlog('snappymail', \LOG_ODELAY, \LOG_USER)) {
\syslog($level, "{$prefix} {$msg}"); \syslog($level, "{$prefix} {$msg}");
\closelog(); \closelog();
} }
*/
if (\filter_var(\ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) if (\filter_var(\ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN)
&& (($level < \LOG_WARNING && \error_reporting() & \E_ERROR) && (($level < \LOG_WARNING && \error_reporting() & \E_ERROR)
|| ($level == \LOG_WARNING && \error_reporting() & \E_WARNING) || ($level == \LOG_WARNING && \error_reporting() & \E_WARNING)
|| ($level > \LOG_WARNING && \error_reporting() & \E_NOTICE) || ($level > \LOG_WARNING && \error_reporting() & \E_NOTICE)
)) { )) {
\error_log($prefix . ' ' . static::$levels[$level] . ': ' . $msg); \error_log($prefix . ' ' . static::$levels[$level] . ': ' . $msg);
// \error_log($prefix . ' ' . static::$levels[$level] . ': ' . $msg, 3, 'filename');
} }
} }
*/
} }
} }

View file

@ -143,7 +143,7 @@ abstract class Repository
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
$sError = "{$e->getCode()} {$e->getMessage()}"; $sError = "{$e->getCode()} {$e->getMessage()}";
\RainLoop\Api::Logger()->Write($sError, \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER'); \RainLoop\Api::Logger()->Write($sError, \LOG_ERR, 'INSTALLER');
} }
return $aResult; return $aResult;
} }
@ -246,7 +246,7 @@ abstract class Repository
{ {
empty($_ENV['SNAPPYMAIL_INCLUDE_AS_API']) && \RainLoop\Api::Actions()->IsAdminLoggined(); empty($_ENV['SNAPPYMAIL_INCLUDE_AS_API']) && \RainLoop\Api::Actions()->IsAdminLoggined();
\RainLoop\Api::Logger()->Write('Start package install: '.$sId.' ('.$sType.')', \MailSo\Log\Enumerations\Type::INFO, 'INSTALLER'); \RainLoop\Api::Logger()->Write('Start package install: '.$sId.' ('.$sType.')', \LOG_INFO, 'INSTALLER');
$sRealFile = ''; $sRealFile = '';
@ -281,7 +281,7 @@ abstract class Repository
} }
} }
} catch (\Throwable $e) { } catch (\Throwable $e) {
\RainLoop\Api::Logger()->Write("Install package {$sRealFile} failed: {$e->getMessage()}", \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER'); \RainLoop\Api::Logger()->Write("Install package {$sRealFile} failed: {$e->getMessage()}", \LOG_ERR, 'INSTALLER');
throw $e; throw $e;
} finally { } finally {
$sTmp && \unlink($sTmp); $sTmp && \unlink($sTmp);