Пример #1
0
 /**
  * @param string $sDesc
  * @param int $iLogLevel = ELogLevel::Full
  * @param string $sFilePrefix = ''
  * @param bool $bIdDb = false
  */
 public static function Log($sDesc, $iLogLevel = ELogLevel::Full, $sFilePrefix = '')
 {
     static $bIsFirst = true;
     $oSettings =& CApi::GetSettings();
     if ($oSettings && $oSettings->GetConf('EnableLogging') && ($iLogLevel <= $oSettings->GetConf('LoggingLevel') || ELogLevel::Spec === $oSettings->GetConf('LoggingLevel') && isset($_COOKIE['SpecifiedUserLogging']) && '1' === (string) $_COOKIE['SpecifiedUserLogging'])) {
         $sLogFile = self::GetLogFileName($sFilePrefix);
         $sGuid = \MailSo\Log\Logger::Guid();
         $aMicro = explode('.', microtime(true));
         $sDate = gmdate('H:i:s.') . str_pad(isset($aMicro[1]) ? substr($aMicro[1], 0, 2) : '0', 2, '0');
         if ($bIsFirst) {
             $sUri = api_Utils::RequestUri();
             $bIsFirst = false;
             $sPost = isset($_POST) && count($_POST) > 0 ? '[POST(' . count($_POST) . ')]' : '[GET]';
             CApi::LogOnly(API_CRLF . '[' . $sDate . '][' . $sGuid . '] ' . $sPost . '[ip:' . (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown') . '] ' . $sUri, $sLogFile);
             if (!empty($sPost)) {
                 if (CApi::GetConf('labs.log.post-view', false)) {
                     CApi::LogOnly('[' . $sDate . '][' . $sGuid . '] POST > ' . print_r($_POST, true), $sLogFile);
                 } else {
                     CApi::LogOnly('[' . $sDate . '][' . $sGuid . '] POST > [' . implode(', ', array_keys($_POST)) . ']', $sLogFile);
                 }
             }
             CApi::LogOnly('[' . $sDate . '][' . $sGuid . ']', $sLogFile);
             //				@register_shutdown_function('CApi::LogEnd');
         }
         CApi::LogOnly('[' . $sDate . '][' . $sGuid . '] ' . (is_string($sDesc) ? $sDesc : print_r($sDesc, true)), $sLogFile);
     }
 }
Пример #2
0
 /**
  * @param string $sTimePrefix
  * @param string $sDesc
  * @param int $iType = \MailSo\Log\Enumerations\Type::INFO
  * @param array $sName = ''
  *
  * @return string
  */
 protected function loggerLineImplementation($sTimePrefix, $sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
 {
     return \ltrim(($this->bTimePrefix ? '[' . $sTimePrefix . ']' : '') . ($this->bGuidPrefix ? '[' . \MailSo\Log\Logger::Guid() . ']' : '') . ($this->bTypedPrefix ? ' ' . $this->getTypedPrefix($iType, $sName) : '')) . $sDesc;
 }
Пример #3
0
 /**
  * @return \MailSo\Log\Logger
  */
 public function Logger()
 {
     if (null === $this->oLogger) {
         $this->oLogger = \MailSo\Log\Logger::SingletonInstance();
         if (!!$this->Config()->Get('logs', 'enable', true)) {
             $this->oLogger->SetShowSecter(!$this->Config()->Get('logs', 'hide_passwords', true));
             $sLogFileFullPath = \APP_PRIVATE_DATA . 'logs/' . $this->compileLogFileName();
             $sLogFileDir = \dirname($sLogFileFullPath);
             if (!@is_dir($sLogFileDir)) {
                 @mkdir($sLogFileDir, 0755, true);
             }
             $this->oLogger->Add(\MailSo\Log\Drivers\File::NewInstance($sLogFileFullPath)->WriteOnErrorOnly($this->Config()->Get('logs', 'write_on_error_only', true))->WriteOnTimeoutOnly($this->Config()->Get('logs', 'write_on_timeout_only', 30)));
             if (!$this->Config()->Get('debug', 'enable', false)) {
                 $this->oLogger->AddForbiddenType(\MailSo\Log\Enumerations\Type::TIME);
             }
             $this->oLogger->WriteEmptyLine();
             $oHttp = $this->Http();
             $this->oLogger->Write('[DATE:' . \gmdate('d.m.y') . '][RL:' . APP_VERSION . '][PHP:' . PHP_VERSION . '][IP:' . $oHttp->GetClientIp() . '][PID:' . (\MailSo\Base\Utils::FunctionExistsAndEnabled('getmypid') ? \getmypid() : 'unknown') . '][GUID:' . \MailSo\Log\Logger::Guid() . ']');
             $this->oLogger->Write('[' . $oHttp->GetMethod() . '] ' . $oHttp->GetScheme() . '://' . $oHttp->GetHost(false, false) . $oHttp->GetServer('REQUEST_URI', ''), \MailSo\Log\Enumerations\Type::NOTE, 'REQUEST');
         }
     }
     return $this->oLogger;
 }