From 87d01c8bdee34ecce636ecd0afc933ccbb6bbfe9 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Sat, 15 Oct 2022 17:39:49 +0200 Subject: [PATCH] Solve the massive logger bloat by simplifying it to be RFC 5424 As it confused people and #552 --- .../files/usr/local/include/application.ini | 10 - .../change-password-hmailserver/driver.php | 6 +- plugins/change-password-poppassd/driver.php | 17 +- plugins/change-password/drivers/ldap.php | 2 +- plugins/change-password/index.php | 2 +- plugins/example/index.php | 4 +- .../LdapContactsSuggestions.php | 6 +- plugins/ldap-identities/LdapIdentities.php | 13 +- plugins/ldap-login-mapping/index.php | 25 +- plugins/login-oauth2/index.php | 4 +- .../0.0.0/app/libraries/MailSo/Base/Utils.php | 37 +-- .../v/0.0.0/app/libraries/MailSo/Config.php | 5 - .../MailSo/Imap/Commands/Folders.php | 4 +- .../MailSo/Imap/Commands/Messages.php | 13 +- .../app/libraries/MailSo/Imap/ImapClient.php | 28 +- .../MailSo/Imap/Requests/ESEARCH.php | 9 +- .../libraries/MailSo/Imap/Requests/SORT.php | 9 +- .../libraries/MailSo/Imap/Requests/THREAD.php | 4 +- .../MailSo/Imap/Traits/ResponseParser.php | 17 +- .../0.0.0/app/libraries/MailSo/Log/Driver.php | 249 ++---------------- .../libraries/MailSo/Log/Drivers/Callback.php | 62 ----- .../app/libraries/MailSo/Log/Drivers/File.php | 18 +- .../libraries/MailSo/Log/Drivers/Inline.php | 64 ----- .../MailSo/Log/Enumerations/Type.php | 24 +- .../0.0.0/app/libraries/MailSo/Log/Logger.php | 140 ++++------ .../app/libraries/MailSo/Net/NetClient.php | 59 ++--- .../MailSo/Sieve/ManageSieveClient.php | 14 +- .../app/libraries/MailSo/Smtp/SmtpClient.php | 26 +- .../0.0.0/app/libraries/RainLoop/Actions.php | 101 ++----- .../libraries/RainLoop/Actions/Messages.php | 13 +- .../libraries/RainLoop/Actions/UserAuth.php | 16 +- .../app/libraries/RainLoop/ActionsAdmin.php | 14 +- .../v/0.0.0/app/libraries/RainLoop/Api.php | 19 +- .../libraries/RainLoop/Common/PdoAbstract.php | 2 +- .../libraries/RainLoop/Config/Application.php | 5 - .../libraries/RainLoop/Plugins/Manager.php | 12 +- .../Providers/AddressBook/CardDAV.php | 14 +- .../app/libraries/RainLoop/ServiceActions.php | 32 +-- .../v/0.0.0/app/libraries/snappymail/log.php | 24 +- .../app/libraries/snappymail/repository.php | 6 +- 40 files changed, 330 insertions(+), 799 deletions(-) delete mode 100644 snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php delete mode 100644 snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Inline.php diff --git a/.docker/release/files/usr/local/include/application.ini b/.docker/release/files/usr/local/include/application.ini index 6a68e6e4b..00097f243 100644 --- a/.docker/release/files/usr/local/include/application.ini +++ b/.docker/release/files/usr/local/include/application.ini @@ -156,20 +156,10 @@ enable = Off ; 7 = Debug 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. ; Disabling this option is not recommended. hide_passwords = On time_zone = "UTC" -session_filter = "" ; Log filename. ; For security reasons, some characters are removed from filename. diff --git a/plugins/change-password-hmailserver/driver.php b/plugins/change-password-hmailserver/driver.php index 59461f73d..b0e30a6d5 100644 --- a/plugins/change-password-hmailserver/driver.php +++ b/plugins/change-password-hmailserver/driver.php @@ -66,13 +66,13 @@ class ChangePasswordHMailServerDriver $oHmailAccount->Save(); $bResult = true; } 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 { - $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 { - $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) diff --git a/plugins/change-password-poppassd/driver.php b/plugins/change-password-poppassd/driver.php index c087e9673..d5661d5b8 100644 --- a/plugins/change-password-poppassd/driver.php +++ b/plugins/change-password-poppassd/driver.php @@ -53,7 +53,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient if ($this->bIsLoggined) { $this->writeLogException( new \RuntimeException('Already authenticated for this session'), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } try @@ -63,7 +63,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient } catch (\Throwable $oException) { - $this->writeLogException($oException, \MailSo\Log\Enumerations\Type::NOTICE, true); + $this->writeLogException($oException, \LOG_NOTICE, true); } $this->bIsLoggined = true; @@ -73,7 +73,7 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient } else { $this->writeLogException( 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); if (!\strlen($sCommand)) { - $this->writeLogException( - new \MailSo\Base\Exceptions\InvalidArgumentException(), - \MailSo\Log\Enumerations\Type::ERROR, true); + $this->writeLogException(new \MailSo\Base\Exceptions\InvalidArgumentException(), \LOG_ERR, true); } $this->IsConnected(true); @@ -158,13 +156,10 @@ class ChangePasswordPoppassdDriver extends \MailSo\Net\NetClient } if (!$bResult) { - $this->writeLogException( - new \MailSo\Base\Exceptions\Exception(), - \MailSo\Log\Enumerations\Type::WARNING, true); + $this->writeLogException(new \MailSo\Base\Exceptions\Exception(), \LOG_WARNING, true); } - $this->writeLog((\microtime(true) - $this->iRequestTime), - \MailSo\Log\Enumerations\Type::TIME); + $this->writeLog((\microtime(true) - $this->iRequestTime), \LOG_DEBUG); return $this; } diff --git a/plugins/change-password/drivers/ldap.php b/plugins/change-password/drivers/ldap.php index e1fc347c4..591f10251 100644 --- a/plugins/change-password/drivers/ldap.php +++ b/plugins/change-password/drivers/ldap.php @@ -79,7 +79,7 @@ class ChangePasswordDriverLDAP if (!\ldap_set_option($oCon, LDAP_OPT_PROTOCOL_VERSION, 3)) { $this->oLogger->Write( 'Failed to set LDAP Protocol version to 3, TLS not supported.', - \MailSo\Log\Enumerations\Type::WARNING, + \LOG_WARNING, 'LDAP' ); } diff --git a/plugins/change-password/index.php b/plugins/change-password/index.php index 1a1e20b95..47ecac4fd 100644 --- a/plugins/change-password/index.php +++ b/plugins/change-password/index.php @@ -183,7 +183,7 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin if ($oLogger) { $oLogger->Write("ERROR: {$name} password change for {$oAccount->Email()} failed"); $oLogger->WriteException($oException); -// $oLogger->WriteException($oException, \MailSo\Log\Enumerations\Type::WARNING, $name); +// $oLogger->WriteException($oException, \LOG_WARNING, $name); } } } diff --git a/plugins/example/index.php b/plugins/example/index.php index 7bb6a2b68..2b6cb1512 100644 --- a/plugins/example/index.php +++ b/plugins/example/index.php @@ -202,7 +202,7 @@ class ExamplePlugin extends \RainLoop\Plugins\AbstractPlugin $this->Manager()->IsEnabled() : bool $this->Manager()->Count() : int $this->Manager()->SetLogger(\MailSo\Log\Logger $oLogger) : self - $this->Manager()->WriteLog(string $sDesc, int $iType = \MailSo\Log\Enumerations\Type::INFO) : void - $this->Manager()->WriteException(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 = \LOG_INFO) : void */ } diff --git a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php index fda5ba309..645d1f8c3 100644 --- a/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php +++ b/plugins/ldap-contacts-suggestions/LdapContactsSuggestions.php @@ -191,7 +191,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges $oCon = @\ldap_connect($this->sLdapUri); 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); @@ -268,7 +268,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges $sFilter .= (1 < count($aItems) ? '(|' : '').$sSubFilter.(1 < count($aItems) ? ')' : ''); $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); if ($oS) { @@ -343,7 +343,7 @@ class LdapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISugges $iErrno = $oCon ? @\ldap_errno($oCon) : 0; $this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')', - \MailSo\Log\Enumerations\Type::WARNING, 'LDAP'); + \LOG_WARNING, 'LDAP'); } } diff --git a/plugins/ldap-identities/LdapIdentities.php b/plugins/ldap-identities/LdapIdentities.php index 887f94bed..04ced2cb8 100644 --- a/plugins/ldap-identities/LdapIdentities.php +++ b/plugins/ldap-identities/LdapIdentities.php @@ -1,6 +1,5 @@ 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; } @@ -77,10 +76,10 @@ class LdapIdentities implements IIdentities } 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 []; } 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]; @@ -219,7 +218,7 @@ class LdapIdentities implements IIdentities $errorMsg = @ldap_error($this->ldap); $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); } @@ -279,14 +278,14 @@ class LdapIdentities implements IIdentities { if (!isset($entry[$attribute])) { 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 ? "" : []; } if ($single) { 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]; } diff --git a/plugins/ldap-login-mapping/index.php b/plugins/ldap-login-mapping/index.php index a0d8e5ac6..e3aeb2e8c 100644 --- a/plugins/ldap-login-mapping/index.php +++ b/plugins/ldap-login-mapping/index.php @@ -1,8 +1,7 @@ oLogger = \MailSo\Log\Logger::SingletonInstance(); + $this->oLogger = \RainLoop\Api::Logger(); $this->aDomains = explode(',', $this->Config()->Get('plugin', 'domains', '')); $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)) { - $sIP = $_SERVER['REMOTE_ADDR']; - $sResult = $this->ldapSearch($sEmail); + $sIP = $_SERVER['REMOTE_ADDR']; + $sResult = $this->ldapSearch($sEmail); if ( is_array($sResult) ) { $sLogin = $sResult['login']; $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; foreach ( $this->aDomains as $sDomain ) { $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) { $bFound = TRUE; break; @@ -172,18 +171,18 @@ class LDAPLoginMappingPlugin extends AbstractPlugin if ( !$bFound ) { $this->oLogger->Write( 'preg_match: no match in "' . $sEmail . '" for /^[a-z0-9._-]+@{configured-domains}$/i', - Type::INFO, + \LOG_INFO, 'LDAP'); return FALSE; } $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); 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); @@ -199,7 +198,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin } else { $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); if (!$oS) { $this->logLdapError($oCon, 'ldap_search'); @@ -246,7 +245,7 @@ class LDAPLoginMappingPlugin extends AbstractPlugin $iErrno = $oCon ? @\ldap_errno($oCon) : 0; $this->oLogger->Write($sCmd.' error: '.$sError.' ('.$iErrno.')', - Type::WARNING, 'LDAP'); + \LOG_WARNING, 'LDAP'); } } diff --git a/plugins/login-oauth2/index.php b/plugins/login-oauth2/index.php index 2c266833d..cb92e1f24 100644 --- a/plugins/login-oauth2/index.php +++ b/plugins/login-oauth2/index.php @@ -194,7 +194,7 @@ class LoginOAuth2Plugin extends \RainLoop\Plugins\AbstractPlugin } 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) { - $oActions->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); + $oActions->Logger()->WriteException($oException, \LOG_ERR); } $oActions = \RainLoop::Actions(); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php index 706df4bf0..40a03596a 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Utils.php @@ -802,7 +802,7 @@ abstract class Utils return false; } - public static function ClearArrayUtf8Values(array &$aInput) + private static function ClearArrayUtf8Values(array &$aInput) { foreach ($aInput as $mKey => $mItem) { @@ -824,35 +824,20 @@ abstract class Utils public static function Php2js($mInput, ?\MailSo\Log\Logger $oLogger = null) : string { $sResult = \json_encode($mInput, JSON_UNESCAPED_UNICODE); - if (!\is_string($sResult) || '' === $sResult) - { - if (!$oLogger && \MailSo\Log\Logger::IsSystemEnabled()) - { - $oLogger = \MailSo\Config::$SystemLogger; - } - - if ($oLogger) - { - $oLogger->Write('json_encode: '.\trim( - (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'); - } - + if (!\is_string($sResult) || '' === $sResult) { + \trigger_error( + 'json_encode: '.\trim( + (static::FunctionExistsAndEnabled('json_last_error') ? ' [Error Code: '.\json_last_error().']' : ''). + (static::FunctionExistsAndEnabled('json_last_error_msg') ? ' [Error Message: '.\json_last_error_msg().']' : '') + ), E_USER_WARNING + ); + if (\is_array($mInput)) { +// $oLogger->WriteDump($mInput, \LOG_INFO, 'JSON'); +// $oLogger->Write('Trying to clear Utf8 before json_encode', \LOG_INFO, 'JSON'); static::ClearArrayUtf8Values($mInput); $sResult = \json_encode($mInput, JSON_UNESCAPED_UNICODE); } } - return $sResult; } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Config.php b/snappymail/v/0.0.0/app/libraries/MailSo/Config.php index 5695c40ac..5a8c23f71 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Config.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Config.php @@ -70,9 +70,4 @@ class Config * @var int */ public static $ImapTimeout = 300; - - /** - * @var \MailSo\Log\Logger|null - */ - public static $SystemLogger = null; } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php index 642e5f52a..dbcf96539 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Folders.php @@ -508,11 +508,11 @@ trait Folders } catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException) { - $this->writeLogException($oException, \MailSo\Log\Enumerations\Type::WARNING, false); + $this->writeLogException($oException, \LOG_WARNING, false); } catch (\Throwable $oException) { - $this->writeLogException($oException, \MailSo\Log\Enumerations\Type::WARNING, false); + $this->writeLogException($oException, \LOG_WARNING, false); } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php index f2052e7c6..f1233f36c 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php @@ -17,7 +17,6 @@ use MailSo\Imap\Enumerations\FetchType; use MailSo\Imap\ResponseCollection; use MailSo\Imap\SequenceSet; use MailSo\Imap\Enumerations\ResponseType; -use MailSo\Log\Enumerations\Type as LogType; use MailSo\Base\Exceptions\InvalidArgumentException; /** @@ -35,7 +34,7 @@ trait Messages { if (!\strlen(\trim($sIndexRange))) { - $this->writeLogException(new InvalidArgumentException, LogType::ERROR, true); + $this->writeLogException(new InvalidArgumentException, \LOG_ERR, true); } $aReturn = array(); @@ -115,7 +114,7 @@ trait Messages if (FetchResponse::hasUidAndSize($oResponse)) { $aReturn[] = new FetchResponse($oResponse); } 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 { - $this->writeLog('Write to connection stream', LogType::NOTE); + $this->writeLog('Write to connection stream', \LOG_INFO); \MailSo\Base\Utils::MultipleStreamWriter($rMessageStream, array($this->ConnectionResource())); @@ -198,7 +197,7 @@ trait Messages public function MessageCopy(string $sToFolder, SequenceSet $oRange) : ResponseCollection { if (!\count($oRange)) { - $this->writeLogException(new InvalidArgumentException, LogType::ERROR, true); + $this->writeLogException(new InvalidArgumentException, \LOG_ERR, true); } return $this->SendRequestGetResponse( @@ -215,13 +214,13 @@ trait Messages public function MessageMove(string $sToFolder, SequenceSet $oRange) : ResponseCollection { if (!\count($oRange)) { - $this->writeLogException(new InvalidArgumentException, LogType::ERROR, true); + $this->writeLogException(new InvalidArgumentException, \LOG_ERR, true); } if (!$this->IsSupported('MOVE')) { $this->writeLogException( new \MailSo\IMAP\Exceptions\RuntimeException('Move is not supported'), - LogType::ERROR, true); + \LOG_ERR, true); } return $this->SendRequestGetResponse( diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index 600097313..45561cc92 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -103,7 +103,7 @@ class ImapClient extends \MailSo\Net\NetClient { $this->writeLogException( 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( new \MailSo\Base\Exceptions\InvalidArgumentException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->sLogginedUser = $sLogin; @@ -199,7 +199,7 @@ class ImapClient extends \MailSo\Net\NetClient if ($oR && Enumerations\ResponseType::CONTINUATION === $oR->ResponseType) { if (!empty($oR->ResponseList[1]) && preg_match('/^[a-zA-Z0-9=+\/]+$/', $oR->ResponseList[1])) { $this->Logger()->Write(\base64_decode($oR->ResponseList[1]), - \MailSo\Log\Enumerations\Type::WARNING); + \LOG_WARNING); } $this->sendRaw(''); $oResponse = $this->getResponse(); @@ -254,7 +254,7 @@ class ImapClient extends \MailSo\Net\NetClient $this->writeLogException( new Exceptions\LoginBadCredentialsException( $oException->GetResponses(), '', 0, $oException), - \MailSo\Log\Enumerations\Type::NOTICE, true); + \LOG_NOTICE, true); } $this->bIsLoggined = true; @@ -364,7 +364,7 @@ class ImapClient extends \MailSo\Net\NetClient } throw new Exceptions\ResponseException; } catch (\Throwable $e) { - $this->writeLogException($e, \MailSo\Log\Enumerations\Type::ERROR); + $this->writeLogException($e, \LOG_ERR); throw $e; } } @@ -409,7 +409,7 @@ class ImapClient extends \MailSo\Net\NetClient { $this->writeLogException( new \MailSo\Base\Exceptions\InvalidArgumentException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->IsConnected(true); @@ -475,11 +475,11 @@ class ImapClient extends \MailSo\Net\NetClient } $this->writeLogException( new Exceptions\LoginException, - \MailSo\Log\Enumerations\Type::NOTICE, true); + \LOG_NOTICE, true); } $this->writeLogException( new Exceptions\LoginException, - \MailSo\Log\Enumerations\Type::NOTICE, true); + \LOG_NOTICE, true); } /** @@ -509,7 +509,7 @@ class ImapClient extends \MailSo\Net\NetClient exit; } } catch (\Throwable $e) { - $this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING); + $this->writeLogException($e, \LOG_WARNING); throw $e; } } @@ -534,8 +534,7 @@ class ImapClient extends \MailSo\Net\NetClient if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) { if (isset($this->aTagTimeouts[$sEndTag])) { - $this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', - \MailSo\Log\Enumerations\Type::TIME); + $this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', \LOG_DEBUG); unset($this->aTagTimeouts[$sEndTag]); } @@ -548,7 +547,7 @@ class ImapClient extends \MailSo\Net\NetClient $oResult->validate(); } catch (\Throwable $e) { - $this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING); + $this->writeLogException($e, \LOG_WARNING); throw $e; } @@ -580,8 +579,7 @@ class ImapClient extends \MailSo\Net\NetClient if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) { if (isset($this->aTagTimeouts[$sEndTag])) { - $this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', - \MailSo\Log\Enumerations\Type::TIME); + $this->writeLog((\microtime(true) - $this->aTagTimeouts[$sEndTag]).' ('.$sEndTag.')', \LOG_DEBUG); unset($this->aTagTimeouts[$sEndTag]); } @@ -594,7 +592,7 @@ class ImapClient extends \MailSo\Net\NetClient $oResult->validate(); } catch (\Throwable $e) { - $this->writeLogException($e, \MailSo\Log\Enumerations\Type::WARNING); + $this->writeLogException($e, \LOG_WARNING); throw $e; } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/ESEARCH.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/ESEARCH.php index a611aeba8..c484219bc 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/ESEARCH.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/ESEARCH.php @@ -13,7 +13,6 @@ namespace MailSo\Imap\Requests; use MailSo\Imap\Exceptions\RuntimeException; -use MailSo\Log\Enumerations\Type; /** * @category MailSo @@ -58,7 +57,7 @@ class ESEARCH extends Request if (!$oImapClient->IsSupported('ESEARCH')) { $oImapClient->writeLogException( new RuntimeException('ESEARCH is not supported'), - Type::ERROR, true); + \LOG_ERR, true); } parent::__construct($oImapClient); } @@ -72,7 +71,7 @@ class ESEARCH extends Request if (false !== \stripos($this->sCriterias, 'FUZZY') && !$this->oImapClient->IsSupported('SEARCH=FUZZY')) { $this->oImapClient->writeLogException( 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')) { $this->oImapClient->writeLogException( new RuntimeException('MULTISEARCH is not supported'), - Type::ERROR, true); + \LOG_ERR, true); } $sCmd = 'ESEARCH'; $aReques[] = 'IN'; @@ -113,7 +112,7 @@ class ESEARCH extends Request if (\preg_match('/PARTIAL|UPDATE|CONTEXT/i', $sReturn)) { $this->oImapClient->writeLogException( new RuntimeException('CONTEXT=SEARCH is not supported'), - Type::ERROR, true); + \LOG_ERR, true); } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/SORT.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/SORT.php index 51cb90d1c..5cea3b477 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/SORT.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/SORT.php @@ -16,7 +16,6 @@ namespace MailSo\Imap\Requests; use MailSo\Imap\Exceptions\RuntimeException; -use MailSo\Log\Enumerations\Type; /** * @category MailSo @@ -59,7 +58,7 @@ class SORT extends Request if (!$oImapClient->IsSupported('SORT')) { $oImapClient->writeLogException( new RuntimeException('SORT is not supported'), - Type::ERROR, true); + \LOG_ERR, true); } parent::__construct($oImapClient); } @@ -69,7 +68,7 @@ class SORT extends Request if (!$this->aSortTypes) { $this->oImapClient->writeLogException( new RuntimeException('SortTypes are missing'), - Type::ERROR, true); + \LOG_ERR, true); } $aRequest = array(); @@ -79,14 +78,14 @@ class SORT extends Request if (!$this->oImapClient->IsSupported('ESORT')) { $this->oImapClient->writeLogException( new RuntimeException('ESORT is not supported'), - Type::ERROR, true); + \LOG_ERR, true); } if (!$this->oImapClient->IsSupported('CONTEXT=SORT')) { foreach ($this->aReturn as $sReturn) { if (\preg_match('/PARTIAL|UPDATE|CONTEXT/i', $sReturn)) { $this->oImapClient->writeLogException( new RuntimeException('CONTEXT=SORT is not supported'), - Type::ERROR, true); + \LOG_ERR, true); } } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/THREAD.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/THREAD.php index 818258c1c..0029527a3 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/THREAD.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Requests/THREAD.php @@ -36,7 +36,7 @@ class THREAD extends Request } else { $oImapClient->writeLogException( new \MailSo\Imap\Exceptions\RuntimeException('THREAD is not supported'), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } parent::__construct($oImapClient); } @@ -46,7 +46,7 @@ class THREAD extends Request if (!$this->oImapClient->IsSupported(\strtoupper("THREAD={$this->sAlgorithm}"))) { $this->oImapClient->writeLogException( new \MailSo\Imap\Exceptions\RuntimeException("THREAD={$this->sAlgorithm} is not supported"), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->oImapClient->SendRequest( diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php index 12e1adeb9..fcff6b5a4 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Traits/ResponseParser.php @@ -184,14 +184,14 @@ trait ResponseParser if (!$bTreatAsAtom) { $aList[] = $sLiteral; if (\MailSo\Config::$LogSimpleLiterals) { - $this->writeLog('{'.$iLiteralLen.'} '.$sLiteral, \MailSo\Log\Enumerations\Type::INFO); + $this->writeLog('{'.$iLiteralLen.'} '.$sLiteral, \LOG_INFO); } } else { \SnappyMail\Log::notice('IMAP', 'Literal treated as atom and skipped'); } unset($sLiteral); } 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); if (!$iBLen) { $this->writeLog('Literal stream read warning "read '.\strlen($sLiteral).' of '. - $iLiteralLen.'" bytes', \MailSo\Log\Enumerations\Type::WARNING); + $iLiteralLen.'" bytes', \LOG_WARNING); return null; } $sLiteral .= $sAddRead; @@ -373,7 +373,7 @@ trait ResponseParser $iLiteralSize = \strlen($sLiteral); if ($iLiteralLen !== $iLiteralSize) { $this->writeLog('Literal stream read warning "read '.$iLiteralSize.' of '. - $iLiteralLen.'" bytes', \MailSo\Log\Enumerations\Type::WARNING); + $iLiteralLen.'" bytes', \LOG_WARNING); } return $sLiteral; } @@ -403,7 +403,7 @@ trait ResponseParser \MailSo\Base\StreamWrappers\Literal::CreateStream($this->ConnectionResource(), $iLiteralLen); $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; @@ -413,7 +413,6 @@ trait ResponseParser } catch (\Throwable $oException) { - $this->writeLog('Callback Exception', \MailSo\Log\Enumerations\Type::NOTICE); $this->writeLogException($oException); } @@ -423,7 +422,7 @@ trait ResponseParser $bFeof = \feof($rImapLiteralStream); $this->writeLog('End Callback for '.$sParent.' / '.$sLiteralAtomUpperCase. ' - feof = '.($bFeof ? 'good' : 'BAD'), $bFeof ? - \MailSo\Log\Enumerations\Type::NOTE : \MailSo\Log\Enumerations\Type::WARNING); + \LOG_INFO : \LOG_WARNING); if (!$bFeof) { while (!\feof($rImapLiteralStream)) { @@ -445,11 +444,11 @@ trait ResponseParser if (0 < $iNotReadLiteralLen) { $this->writeLog('Not read literal size is '.$iNotReadLiteralLen.' bytes.', - \MailSo\Log\Enumerations\Type::WARNING); + \LOG_WARNING); } } else { $this->writeLog('Literal stream is not resource after callback.', - \MailSo\Log\Enumerations\Type::WARNING); + \LOG_WARNING); } $this->bRunningCallback = false; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Driver.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Driver.php index 04da9da03..94e773b4c 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Driver.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Driver.php @@ -20,22 +20,31 @@ abstract class Driver /** * @var string */ - protected $sDatePattern; + protected $sDatePattern = 'H:i:s'; /** * @var string */ - protected $sName; + protected $sName = ''; /** * @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 */ - protected $bGuidPrefix; + protected $bGuidPrefix = true; /** * @var DateTimeZone @@ -45,85 +54,23 @@ abstract class Driver /** * @var bool */ - protected $bTimePrefix; + protected $bTimePrefix = true; /** * @var bool */ - protected $bTypedPrefix; - - /** - * @var string - */ - protected $sNewLine; - - /** - * @var int - */ - private $iWriteOnTimeoutOnly; - - /** - * @var bool - */ - private $bWriteOnErrorOnly; - - /** - * @var bool - */ - private $bWriteOnPhpErrorOnly; - - /** - * @var bool - */ - private $bFlushCache; - - /** - * @var array - */ - private $aCache; + protected $bTypedPrefix = true; 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->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 = $oTimeZone; - } else { - $this->oTimeZone = new \DateTimeZone($oTimeZone); - } + $this->oTimeZone = $mTimeZone instanceof \DateTimeZone + ? $mTimeZone + : new \DateTimeZone($mTimeZone); return $this; } @@ -139,24 +86,6 @@ abstract class Driver 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 { $this->bTypedPrefix = false; @@ -165,21 +94,6 @@ abstract class Driver 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 { return true; @@ -193,129 +107,24 @@ abstract class Driver protected function getTypedPrefix(int $iType, string $sName = '') : string { $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) - { - if (\is_array($mDesc)) - { - foreach ($mDesc as &$sLine) - { - $sLine = \strtr($sLine, array("\r" => '\r', "\n" => '\n'.$this->sNewLine)); - $sLine = \rtrim($sLine); - } - } - else - { - $mDesc = \strtr($mDesc, array("\r" => '\r', "\n" => '\n'.$this->sNewLine)); - $mDesc = \rtrim($mDesc); - } + $sDesc = \ltrim( + ($this->bTimePrefix ? '['.$this->getTimeWithMicroSec().']' : ''). + ($this->bGuidPrefix ? '['.Logger::Guid().']' : ''). + ($this->bTypedPrefix ? ' '.$this->getTypedPrefix($iType, $sName) : '') + ) . $sDesc; + if ($bDiplayCrLf) { + $sDesc = \rtrim(\strtr($sDesc, array("\r" => '\r', "\n" => '\n'."\n"))); } - - 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; + return $this->writeImplementation($sDesc); } final public function Clear() : bool { return $this->clearImplementation(); } - - final public function WriteEmptyLine() : void - { - if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || $this->iWriteOnTimeoutOnly)) - { - $this->aCache[] = ''; - } - else - { - $this->writeEmptyLineImplementation(); - } - } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php deleted file mode 100644 index 27b634ad4..000000000 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Callback.php +++ /dev/null @@ -1,62 +0,0 @@ -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; - } -} diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/File.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/File.php index 831d743bc..5a4a95f55 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/File.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/File.php @@ -23,16 +23,18 @@ class File extends \MailSo\Log\Driver */ private $sLoggerFileName; - function __construct(string $sLoggerFileName, string $sNewLine = "\r\n") + function __construct(string $sLoggerFileName) { parent::__construct(); - - $this->sLoggerFileName = $sLoggerFileName; - $this->sNewLine = $sNewLine; + $this->SetLoggerFileName($sLoggerFileName); } public function SetLoggerFileName(string $sLoggerFileName) { + $sLogFileDir = \dirname($sLoggerFileName); + if (!\is_dir($sLogFileDir)) { + \mkdir($sLogFileDir, 0755, true); + } $this->sLoggerFileName = $sLoggerFileName; } @@ -48,11 +50,9 @@ class File extends \MailSo\Log\Driver private function writeToLogFile($mDesc) : bool { - if (\is_array($mDesc)) - { - $mDesc = \implode($this->sNewLine, $mDesc); + if (\is_array($mDesc)) { + $mDesc = \implode("\n\t", $mDesc); } - - return \error_log($mDesc.$this->sNewLine, 3, $this->sLoggerFileName); + return \error_log($mDesc . "\n", 3, $this->sLoggerFileName); } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Inline.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Inline.php deleted file mode 100644 index e6a39f16f..000000000 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Drivers/Inline.php +++ /dev/null @@ -1,64 +0,0 @@ -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; - } -} diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Enumerations/Type.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Enumerations/Type.php index b90347e0a..10bd5f059 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Enumerations/Type.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Enumerations/Type.php @@ -19,18 +19,14 @@ namespace MailSo\Log\Enumerations; abstract class Type { const - INFO = 0, - NOTICE = 1, - WARNING = 2, - ERROR = 3, - SECURE = 4, - NOTE = 5, - TIME = 6, - MEMORY = 7, - TIME_DELTA = 8, - DEBUG = 9, - - NOTICE_PHP = 11, - WARNING_PHP = 12, - ERROR_PHP = 13; + INFO = \LOG_INFO, // 6 + NOTICE = \LOG_NOTICE, // 5 + WARNING = \LOG_WARNING, // 4 + ERROR = \LOG_ERR, // 3 + SECURE = \LOG_INFO, + NOTE = \LOG_INFO, + TIME = \LOG_DEBUG, + MEMORY = \LOG_INFO, + TIME_DELTA = \LOG_INFO, + DEBUG = \LOG_DEBUG; // 7 } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php index 9b9e1f5ce..4b25f1601 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Log/Logger.php @@ -19,7 +19,7 @@ class Logger extends \SplFixedArray { private $bUsed = false; - private $aForbiddenTypes = []; + private $iLevel = \LOG_WARNING; private $aSecretWords = []; @@ -37,36 +37,6 @@ class Logger extends \SplFixedArray \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; */ @@ -114,43 +84,56 @@ class Logger extends \SplFixedArray return $this->bShowSecrets; } - public function AddForbiddenType(int $iType) : self + public function SetLevel(int $iLevel) : self { - $this->aForbiddenTypes[$iType] = true; - + $this->iLevel = $iLevel; 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 { if (\error_reporting() & $iErrNo) { - $iType = Enumerations\Type::NOTICE_PHP; - switch ($iErrNo) - { - case E_USER_ERROR: - $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'); + $this->Write( + "{$sErrStr} {$sErrFile} [line:{$iErrLine}, code:{$iErrNo}]", + static::PHP_TYPES[$iErrNo], + 'PHP' . static::PHP_TYPE_POSTFIX[$iErrNo] + ); } /* forward to standard PHP error handler */ return false; @@ -158,31 +141,16 @@ class Logger extends \SplFixedArray public function __loggerShutDown() : void { - if ($this->bUsed) - { - $this->Write('Memory peak usage: '.\MailSo\Base\Utils::FormatFileSize(\memory_get_peak_usage(true), 2), - Enumerations\Type::MEMORY); - $this->Write('Time delta: '.(\microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']), Enumerations\Type::TIME_DELTA); + if ($this->bUsed) { + $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'])); } } - public function WriteEmptyLine() : bool - { - $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, + public function Write(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bSearchSecretWords = true, bool $bDiplayCrLf = false) : bool { - if (!empty($this->aForbiddenTypes[$iType])) - { + if ($this->iLevel < $iType) { return true; } @@ -206,13 +174,13 @@ class Logger extends \SplFixedArray /** * @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 { 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 { if ($oException instanceof \Throwable) @@ -230,7 +198,7 @@ class Logger extends \SplFixedArray 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 { if ($oException instanceof \Throwable) @@ -254,12 +222,12 @@ class Logger extends \SplFixedArray public function WriteMixed($mData, int $iType = null, string $sName = '', 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 ($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->WriteDump($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf); diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php index 60610f56d..8e7429103 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Net/NetClient.php @@ -126,14 +126,14 @@ abstract class NetClient if (!\strlen($oSettings->host) || !\MailSo\Base\Validator::PortInt($oSettings->port)) { $this->writeLogException( new \MailSo\Base\Exceptions\InvalidArgumentException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } if ($this->IsConnected()) { $this->writeLogException( new Exceptions\SocketAlreadyConnectedException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $sErrorStr = ''; @@ -155,12 +155,12 @@ abstract class NetClient { $this->writeLogException( 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->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"', - \MailSo\Log\Enumerations\Type::NOTE); + \LOG_INFO); $aStreamContextSettings = array( 'ssl' => $oSettings->ssl @@ -186,7 +186,7 @@ abstract class NetClient \restore_error_handler(); $this->writeLog('Connect ('.($this->rConnect ? 'success' : 'failed').')', - \MailSo\Log\Enumerations\Type::NOTE); + \LOG_INFO); if (!$this->rConnect) { @@ -194,11 +194,10 @@ abstract class NetClient new Exceptions\SocketCanNotConnectToHostException( \MailSo\Base\Locale::ConvertSystemString($sErrorStr), (int) $iErrorNo, '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)', - \MailSo\Log\Enumerations\Type::TIME); + $this->writeLog((\microtime(true) - $this->iStartConnectTime).' (raw connection)', \LOG_DEBUG); if ($this->rConnect) { @@ -228,7 +227,7 @@ abstract class NetClient if ($bError) { $this->writeLogException( 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); $this->writeLog('Disconnected from "'.$this->sConnectedHost.':'.$this->iConnectedPort.'" ('. - (($bResult) ? 'success' : 'unsuccess').')', \MailSo\Log\Enumerations\Type::NOTE); + (($bResult) ? 'success' : 'unsuccess').')', \LOG_INFO); if ($this->iStartConnectTime) { - $this->writeLog((\microtime(true) - $this->iStartConnectTime).' (net session)', - \MailSo\Log\Enumerations\Type::TIME); + $this->writeLog((\microtime(true) - $this->iStartConnectTime).' (net session)', \LOG_DEBUG); $this->iStartConnectTime = 0; } @@ -271,7 +269,7 @@ abstract class NetClient if ($bThrowExceptionOnFalse) { $this->writeLogException( new Exceptions\SocketConnectionDoesNotAvailableException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } return false; } @@ -298,9 +296,7 @@ abstract class NetClient { if ($this->bUnreadBuffer) { - $this->writeLogException( - new Exceptions\SocketUnreadBufferException, - \MailSo\Log\Enumerations\Type::ERROR, true); + $this->writeLogException(new Exceptions\SocketUnreadBufferException, \LOG_ERR, true); } $bFake = \strlen($sFakeRaw); @@ -320,18 +316,11 @@ abstract class NetClient if (false === $mResult) { $this->IsConnected(true); - - $this->writeLogException( - new Exceptions\SocketWriteException, - \MailSo\Log\Enumerations\Type::ERROR, true); + $this->writeLogException(new Exceptions\SocketWriteException, \LOG_ERR, true); } - else + else if ($bWriteToLog) { - if ($bWriteToLog) - { - $this->writeLogWithCrlf('> '.($bFake ? $sFakeRaw : $sRaw), //.' ['.$iWriteSize.']', - $bFake ? \MailSo\Log\Enumerations\Type::SECURE : \MailSo\Log\Enumerations\Type::INFO); - } + $this->writeLogWithCrlf('> '.($bFake ? $sFakeRaw : $sRaw), \LOG_INFO); } } @@ -373,16 +362,16 @@ abstract class NetClient { $this->writeLogException( new Exceptions\SocketReadTimeoutException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } else { $this->writeLog('Stream Meta: '. - \print_r($aSocketStatus, true), \MailSo\Log\Enumerations\Type::ERROR); + \print_r($aSocketStatus, true), \LOG_ERR); $this->writeLogException( new Exceptions\SocketReadException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } } else @@ -394,25 +383,25 @@ abstract class NetClient if ($iLimit < $iReadedLen) { $this->writeLogWithCrlf('[cutted:'.$iReadedLen.'] < '.\substr($this->sResponseBuffer, 0, $iLimit).'...', - \MailSo\Log\Enumerations\Type::INFO); + \LOG_INFO); } else { $this->writeLogWithCrlf('< '.$this->sResponseBuffer, //.' ['.$iReadedLen.']', - \MailSo\Log\Enumerations\Type::INFO); + \LOG_INFO); } } else { $this->writeLog('Received '.$iReadedLen.'/'.$iReadLen.' bytes.', - \MailSo\Log\Enumerations\Type::INFO); + \LOG_INFO); } } } 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) { @@ -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); } 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) { diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php index f37ed69e0..20df57c64 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Sieve/ManageSieveClient.php @@ -83,7 +83,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient { $this->writeLogException( 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( new \MailSo\Base\Exceptions\InvalidArgumentException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } if ($this->IsSupported('SASL')) @@ -176,21 +176,21 @@ class ManageSieveClient extends \MailSo\Net\NetClient $this->writeLogException( new \MailSo\Sieve\Exceptions\LoginBadCredentialsException( $oException->GetResponses(), '', 0, $oException), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } if (!$bAuth) { $this->writeLogException( new \MailSo\Sieve\Exceptions\LoginBadMethodException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } } else { $this->writeLogException( new \MailSo\Sieve\Exceptions\LoginException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->bIsLoggined = true; @@ -449,7 +449,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient { $this->writeLogException( new \MailSo\Base\Exceptions\InvalidArgumentException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->IsConnected(true); @@ -530,7 +530,7 @@ class ManageSieveClient extends \MailSo\Net\NetClient { $this->writeLogException( new \MailSo\Sieve\Exceptions\NegativeResponseException($aResponse), - \MailSo\Log\Enumerations\Type::WARNING, true); + \LOG_WARNING, true); } } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php index 1e3097e63..8f0b94c67 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Smtp/SmtpClient.php @@ -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' : '')); $this->writeLogException( new \MailSo\Smtp\Exceptions\LoginBadMethodException, - \MailSo\Log\Enumerations\Type::NOTICE, true); + \LOG_NOTICE, true); } $SASL = \SnappyMail\SASL::factory($type); @@ -150,7 +150,7 @@ class SmtpClient extends \MailSo\Net\NetClient $this->writeLogException( new \MailSo\Smtp\Exceptions\LoginBadMethodException( $oException->GetResponses(), $oException->getMessage(), 0, $oException), - \MailSo\Log\Enumerations\Type::NOTICE, true); + \LOG_NOTICE, true); } try @@ -178,7 +178,7 @@ class SmtpClient extends \MailSo\Net\NetClient if (empty($sResult)) { $this->writeLogException( new \MailSo\Smtp\Exceptions\NegativeResponseException, - \MailSo\Log\Enumerations\Type::NOTICE, true + \LOG_NOTICE, true ); } $this->sendRequestWithCheck($SASL->authenticate($sLogin, $sPassword, $sResult), 235, '', true); @@ -190,7 +190,7 @@ class SmtpClient extends \MailSo\Net\NetClient $this->writeLogException( new \MailSo\Smtp\Exceptions\LoginBadCredentialsException( $oException->GetResponses(), $oException->getMessage(), 0, $oException), - \MailSo\Log\Enumerations\Type::NOTICE, true); + \LOG_NOTICE, true); } return $this; @@ -236,7 +236,7 @@ class SmtpClient extends \MailSo\Net\NetClient { $this->writeLogException( new Exceptions\RuntimeException('No sender reverse path has been supplied'), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $sTo = \MailSo\Base\Utils::IdnToAscii( @@ -305,12 +305,12 @@ class SmtpClient extends \MailSo\Net\NetClient { $this->writeLogException( new Exceptions\RuntimeException('No recipient forward path has been supplied'), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->sendRequestWithCheck('DATA', 354); - $this->writeLog('Message data.', \MailSo\Log\Enumerations\Type::NOTE); + $this->writeLog('Message data.', \LOG_INFO); $this->bRunningCallback = true; @@ -333,7 +333,7 @@ class SmtpClient extends \MailSo\Net\NetClient { $this->writeLogException( new Exceptions\RuntimeException('Cannot read input resource'), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } break; @@ -411,7 +411,7 @@ class SmtpClient extends \MailSo\Net\NetClient { $this->writeLogException( new Exceptions\RuntimeException('Cannot issue EHLO/HELO to existing session'), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->ehloOrHelo($sEhloHost); @@ -427,7 +427,7 @@ class SmtpClient extends \MailSo\Net\NetClient { $this->writeLogException( new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'), - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->bHelo = true; @@ -443,7 +443,7 @@ class SmtpClient extends \MailSo\Net\NetClient { $this->writeLogException( new \MailSo\Base\Exceptions\InvalidArgumentException, - \MailSo\Log\Enumerations\Type::ERROR, true); + \LOG_ERR, true); } $this->IsConnected(true); @@ -568,7 +568,7 @@ class SmtpClient extends \MailSo\Net\NetClient new Exceptions\NegativeResponseException($this->aResults, ('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim( (\count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : ''). - $this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true); + $this->sResponseBuffer)), \LOG_ERR, true); } } else @@ -577,7 +577,7 @@ class SmtpClient extends \MailSo\Net\NetClient new Exceptions\ResponseException($this->aResults, ('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim( (\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; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index ec56e8bd2..0a75fe9d0 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -122,76 +122,31 @@ class Actions $this->oConfig = API::Config(); $this->oLogger = API::Logger(); - if ($this->oConfig->Get('logs', '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', ''); + if ($this->oConfig->Get('logs', 'enable', false) || $this->oConfig->Get('debug', 'enable', false)) { $oDriver = null; + $sLogFileName = $this->oConfig->Get('logs', 'filename', ''); if ('syslog' === $sLogFileName) { $oDriver = new \MailSo\Log\Drivers\Syslog(); } else { $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); } - $this->oLogger->append($oDriver - ->WriteOnErrorOnly($this->oConfig->Get('logs', 'write_on_error_only', false)) - ->WriteOnPhpErrorOnly($this->oConfig->Get('logs', 'write_on_php_error_only', false)) - ->WriteOnTimeoutOnly($this->oConfig->Get('logs', 'write_on_timeout_only', 0)) - ->SetTimeZone($sTimeZone) + ->SetTimeZone($this->oConfig->Get('logs', 'time_zone', 'UTC')) ); - 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(); - $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( - '[' . $oHttp->GetMethod() . '] ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false, false) . $oHttp->GetServer('REQUEST_URI', ''), - \MailSo\Log\Enumerations\Type::NOTE, 'REQUEST'); + '[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()) + . '][' . $oHttp->GetMethod() . ' ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false, false) . $oHttp->GetServer('REQUEST_URI', '') . ']' + ); } $this->oPlugins = new Plugins\Manager($this); @@ -407,7 +362,7 @@ class Actions { $sFileName = \trim($sFileName); - if (0 !== \strlen($sFileName)) { + if (\strlen($sFileName)) { $sFileName = $this->compileLogParams($sFileName); $sFileName = \preg_replace('/[\/]+/', '/', \preg_replace('/[.]+/', '.', $sFileName)); @@ -415,7 +370,7 @@ class Actions } if (!\strlen($sFileName)) { - $sFileName = 'rainloop-log.txt'; + $sFileName = 'snappymail-log.txt'; } return $sFileName; @@ -602,34 +557,26 @@ class Actions public function LoggerAuth(): \MailSo\Log\Logger { - if (null === $this->oLoggerAuth) { + if (!$this->oLoggerAuth) { $this->oLoggerAuth = new \MailSo\Log\Logger(false); - if ($this->oConfig->Get('logs', 'auth_logging', false)) { +// $this->oLoggerAuth->SetLevel(\LOG_WARNING); + $sAuthLogFileFullPath = \APP_PRIVATE_DATA . 'logs/' . $this->compileLogFileName( $this->oConfig->Get('logs', 'auth_logging_filename', '')); - $sLogFileDir = \dirname($sAuthLogFileFullPath); - - if (!is_dir($sLogFileDir)) { - mkdir($sLogFileDir, 0755, true); + if (!\is_dir($sLogFileDir)) { + \mkdir($sLogFileDir, 0755, true); } - $this->oLoggerAuth - ->AddForbiddenType(\MailSo\Log\Enumerations\Type::MEMORY) - ->AddForbiddenType(\MailSo\Log\Enumerations\Type::TIME) - ->AddForbiddenType(\MailSo\Log\Enumerations\Type::TIME_DELTA); - - $oDriver = new \MailSo\Log\Drivers\File($sAuthLogFileFullPath); - - $oDriver->DisableTimePrefix(); - $oDriver->DisableGuidPrefix(); - $oDriver->DisableTypedPrefix(); - - $this->oLoggerAuth->append($oDriver); + $this->oLoggerAuth->append( + (new \MailSo\Log\Drivers\File($sAuthLogFileFullPath)) + ->DisableTimePrefix() + ->DisableGuidPrefix() + ->DisableTypedPrefix() + ); } } - return $this->oLoggerAuth; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php index fc223131f..63d7dc659 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php @@ -201,7 +201,7 @@ trait Messages } 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) { - $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( + $sMailTo, $sMailSubject, $sMailBody, $sMailHeaders + ), \LOG_DEBUG); $bR = $this->Config()->Get('labs', 'mail_func_additional_parameters', false) ? \mail($sMailTo, $sMailSubject, $sMailBody, $sMailHeaders, '-f'.$oFrom->GetEmail()) : diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php index c83154057..537f3db6e 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/UserAuth.php @@ -33,11 +33,11 @@ trait UserAuth } 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)) { $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; @@ -52,12 +52,12 @@ trait UserAuth if ($oDomain) { $bAdded = true; $this->Logger()->Write('Check "' . $sLine . '": OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')', - \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); + \LOG_INFO, 'LOGIN'); $sEmail .= '@' . $sLine; break; } 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); @@ -70,23 +70,23 @@ trait UserAuth if ($oDomain && $oDomain) { $bAdded = true; $this->Logger()->Write('Check "' . $sLine . '" with wildcard: OK (' . $sEmail . ' > ' . $sEmail . '@' . $sLine . ')', - \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); + \LOG_INFO, 'LOGIN'); $sEmail .= '@' . $sLine; } 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) { - $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', '')); if (!\str_contains($sEmail, '@') && \strlen($sDefDomain)) { $this->Logger()->Write('Default domain "' . $sDefDomain . '" was used. (' . $sEmail . ' > ' . $sEmail . '@' . $sDefDomain . ')', - \MailSo\Log\Enumerations\Type::INFO, 'LOGIN'); + \LOG_INFO, 'LOGIN'); $sEmail .= '@' . $sDefDomain; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php index 6e9f237df..3f05773f9 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ActionsAdmin.php @@ -309,7 +309,7 @@ class ActionsAdmin extends Actions } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { - $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); + $this->Logger()->WriteException($oException, \LOG_ERR); $sImapErrorDesc = $oException->getSocketMessage(); if (empty($sImapErrorDesc)) { @@ -318,7 +318,7 @@ class ActionsAdmin extends Actions } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); + $this->Logger()->WriteException($oException, \LOG_ERR); $sImapErrorDesc = $oException->getMessage(); } @@ -350,7 +350,7 @@ class ActionsAdmin extends Actions } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { - $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); + $this->Logger()->WriteException($oException, \LOG_ERR); $sSmtpErrorDesc = $oException->getSocketMessage(); if (empty($sSmtpErrorDesc)) { @@ -359,7 +359,7 @@ class ActionsAdmin extends Actions } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); + $this->Logger()->WriteException($oException, \LOG_ERR); $sSmtpErrorDesc = $oException->getMessage(); } } @@ -384,7 +384,7 @@ class ActionsAdmin extends Actions } catch (\MailSo\Net\Exceptions\SocketCanNotConnectToHostException $oException) { - $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); + $this->Logger()->WriteException($oException, \LOG_ERR); $sSieveErrorDesc = $oException->getSocketMessage(); if (empty($sSieveErrorDesc)) { @@ -393,7 +393,7 @@ class ActionsAdmin extends Actions } catch (\Throwable $oException) { - $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR); + $this->Logger()->WriteException($oException, \LOG_ERR); $sSieveErrorDesc = $oException->getMessage(); } } @@ -688,7 +688,7 @@ class ActionsAdmin extends Actions if (!$this->Cacher(null, true)->Set(KeyPathHelper::SessionAdminKey($sRand), \time())) { $this->oLogger->Write('Cannot store an admin token', - \MailSo\Log\Enumerations\Type::WARNING); + \LOG_WARNING); return ''; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php index d3b1e6e5e..619540bb6 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Api.php @@ -36,9 +36,10 @@ abstract class Api \usleep(10000); $oConfig->Load(); } +// \ini_set('display_errors', 0); if ($oConfig->Get('debug', 'enable', false)) { \error_reporting(E_ALL); - \ini_set('display_errors', 1); +// \ini_set('display_errors', 1); \ini_set('log_errors', 1); } } @@ -47,7 +48,19 @@ abstract class Api 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 @@ -78,8 +91,6 @@ abstract class Api \MailSo\Config::$BoundaryPrefix = \trim(static::Config()->Get('labs', 'boundary_prefix', '')); - \MailSo\Config::$SystemLogger = static::Logger(); - $sSslCafile = static::Config()->Get('ssl', 'cafile', ''); $sSslCapath = static::Config()->Get('ssl', 'capath', ''); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php index 8459c323d..decbb7575 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Common/PdoAbstract.php @@ -233,7 +233,7 @@ abstract class PdoAbstract { if ($this->oLogger) { - $this->oLogger->WriteMixed($mData, \MailSo\Log\Enumerations\Type::INFO, 'SQL'); + $this->oLogger->WriteMixed($mData, \LOG_INFO, 'SQL'); } } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php index 01ffc1baa..a8a319a4a 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -267,15 +267,10 @@ Values: 6 = Informational 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. Disabling this option is not recommended.'), 'time_zone' => array('UTC'), - 'session_filter' => array(''), 'filename' => array('log-{date:Y-m-d}.txt', 'Log filename. diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php index 12c06c309..9dc10e72c 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php @@ -44,7 +44,6 @@ class Manager $oPlugin = $this->CreatePluginByName($sName); if ($oPlugin) { $oPlugin->Init(); - $this->aPlugins[] = $oPlugin; } else { unset($aList[$i]); @@ -84,6 +83,9 @@ class Manager ->SetPluginManager($this) ->SetPluginConfig(new \RainLoop\Config\Plugin($sName, $oPlugin->ConfigMap(true))) ; + if (\method_exists($oPlugin, 'SetLogger')) { + $oPlugin->SetLogger($this->oLogger); + } } return $oPlugin; @@ -119,7 +121,7 @@ class Manager else { $this->oActions->Logger()->Write('Cannot get installed plugins from '.APP_PLUGINS_PATH, - \MailSo\Log\Enumerations\Type::ERROR); + \LOG_ERR); } return $aList; @@ -316,7 +318,7 @@ class Manager { if ($bLogHook) { - $this->WriteLog('Hook: '.$sHookName, \MailSo\Log\Enumerations\Type::NOTE); + $this->WriteLog('Hook: '.$sHookName, \LOG_INFO); } foreach ($this->aHooks[$sHookName] as $mCallback) @@ -525,7 +527,7 @@ class Manager 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) { @@ -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) { diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php index e2d58d031..453e02026 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/AddressBook/CardDAV.php @@ -28,7 +28,7 @@ trait CardDAV $aResponse = null; 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( '{DAV:}getlastmodified', @@ -100,11 +100,11 @@ trait CardDAV \MailSo\Base\Utils::ResetTimeLimit(); $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) // { -// $this->oLogger->Write($mData, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); +// $this->oLogger->Write($mData, \LOG_INFO, 'DAV'); // } try @@ -122,7 +122,7 @@ trait CardDAV // if ('GET' === $sCmd) // { -// $this->oLogger->WriteDump($aResponse, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); +// $this->oLogger->WriteDump($aResponse, \LOG_INFO, 'DAV'); // } } catch (\Throwable $oException) @@ -139,7 +139,7 @@ trait CardDAV 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( '{DAV:}current-user-principal', @@ -336,7 +336,7 @@ trait CardDAV return false; } - $this->oLogger->Write('PROPFIND '.$sPath, \MailSo\Log\Enumerations\Type::INFO, 'DAV'); + $this->oLogger->Write('PROPFIND '.$sPath, \LOG_INFO, 'DAV'); $aResponse = null; try @@ -412,7 +412,7 @@ trait CardDAV $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; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php index 5184930b9..17718b54b 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/ServiceActions.php @@ -117,7 +117,7 @@ class ServiceActions $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; if ($aPost) @@ -139,7 +139,7 @@ class ServiceActions } */ $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()) { @@ -198,17 +198,17 @@ class ServiceActions { if (\strlen($sObResult)) { - $this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); + $this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA'); } 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); $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; @@ -239,15 +239,15 @@ class ServiceActions $sObResult = \ob_get_clean(); if (\strlen($sObResult)) { - $this->Logger()->Write($sObResult, \MailSo\Log\Enumerations\Type::ERROR, 'OB-DATA'); + $this->Logger()->Write($sObResult, \LOG_ERR, 'OB-DATA'); } 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; } @@ -322,10 +322,10 @@ class ServiceActions $sObResult = \ob_get_clean(); 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; } @@ -443,13 +443,13 @@ class ServiceActions if (\strlen($sRawError)) { - $this->Logger()->Write($sRawError, \MailSo\Log\Enumerations\Type::ERROR); - $this->Logger()->WriteDump($this->aPaths, \MailSo\Log\Enumerations\Type::ERROR, 'PATHS'); + $this->Logger()->Write($sRawError, \LOG_ERR); + $this->Logger()->WriteDump($this->aPaths, \LOG_ERR, 'PATHS'); } if ($oException) { - $this->Logger()->WriteException($oException, \MailSo\Log\Enumerations\Type::ERROR, 'RAW'); + $this->Logger()->WriteException($oException, \LOG_ERR, 'RAW'); } return $sResult; @@ -583,7 +583,7 @@ class ServiceActions } 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(); \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'; } @@ -841,7 +841,7 @@ class ServiceActions .\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; } diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/log.php b/snappymail/v/0.0.0/app/libraries/snappymail/log.php index 29c2dadf7..6e87a02be 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/log.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/log.php @@ -2,8 +2,6 @@ namespace SnappyMail; -use MailSo\Log\Enumerations\Type; - abstract class Log { // Same as RFC 5424 section 6.2.1 decimal Severity level indicator @@ -35,44 +33,32 @@ abstract class Log \LOG_NOTICE => 'NOTICE', \LOG_INFO => 'INFO', \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) { + \RainLoop\Api::Logger()->Write($msg, $level, $prefix); +/* static $log_level; // Default to level 4, 0 = LOG_EMERG, 7 = LOG_DEBUG if (!$log_level) { $log_level = \max(3, \RainLoop\Api::Config()->Get('logs', 'level', \LOG_WARNING)); } 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)) { \syslog($level, "{$prefix} {$msg}"); \closelog(); } -*/ + if (\filter_var(\ini_get('log_errors'), FILTER_VALIDATE_BOOLEAN) && (($level < \LOG_WARNING && \error_reporting() & \E_ERROR) || ($level == \LOG_WARNING && \error_reporting() & \E_WARNING) || ($level > \LOG_WARNING && \error_reporting() & \E_NOTICE) )) { \error_log($prefix . ' ' . static::$levels[$level] . ': ' . $msg); +// \error_log($prefix . ' ' . static::$levels[$level] . ': ' . $msg, 3, 'filename'); } } +*/ } } diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/repository.php b/snappymail/v/0.0.0/app/libraries/snappymail/repository.php index a701fa334..8560fc0a4 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/repository.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/repository.php @@ -143,7 +143,7 @@ abstract class Repository } } catch (\Throwable $e) { $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; } @@ -246,7 +246,7 @@ abstract class Repository { 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 = ''; @@ -281,7 +281,7 @@ abstract class Repository } } } 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; } finally { $sTmp && \unlink($sTmp);