function test_logger()
 {
     if (tx_rnbase_util_Extensions::isLoaded('devlog')) {
         $minLog = tx_rnbase_configurations::getExtensionCfgValue('devlog', 'minLogLevel');
         if ($minLog === FALSE) {
             $ret = tx_rnbase_util_Logger::isNoticeEnabled();
             $this->assertTrue($ret, 'Notice funktioniert nicht.');
         }
         if ($minLog == 1) {
             $ret = tx_rnbase_util_Logger::isNoticeEnabled();
             $this->assertTrue($ret, 'Notice funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isWarningEnabled();
             $this->assertTrue($ret, 'Warning funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isFatalEnabled();
             $this->assertTrue($ret, 'Fatal funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isInfoEnabled();
             $this->assertFalse($ret, 'Info funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isDebugEnabled();
             $this->assertFalse($ret, 'Debug funktioniert nicht.');
         }
         if ($minLog == 3) {
             $ret = tx_rnbase_util_Logger::isNoticeEnabled();
             $this->assertFalse($ret, 'Notice funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isWarningEnabled();
             $this->assertFalse($ret, 'Warning funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isFatalEnabled();
             $this->assertTrue($ret, 'Fatal funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isInfoEnabled();
             $this->assertFalse($ret, 'Info funktioniert nicht.');
             $ret = tx_rnbase_util_Logger::isDebugEnabled();
             $this->assertFalse($ret, 'Debug funktioniert nicht.');
         }
     }
 }
 /**
  * Liefert einen Wert aus der Extension-Konfiguration.
  * Gibt es für die angegebene Extension keine Konfiguration,
  * wird als Fallback der Wert von mklib zurückgegeben.
  *
  * @param string 	$sValueKey
  * @param string 	$sExtKey
  * @param boolean 	$bFallback
  * @return mixed
  */
 public static function getExtensionValue($sValueKey, $sExtKey = 'mklib', $bFallback = false)
 {
     if (!$sExtKey) {
         $sExtKey = 'mklib';
     }
     tx_rnbase::load('tx_rnbase_configurations');
     $mValue = tx_rnbase_configurations::getExtensionCfgValue($sExtKey, $sValueKey);
     if ($bFallback && $mValue === false && $sExtKey != 'mklib') {
         $mValue = tx_rnbase_configurations::getExtensionCfgValue('mklib', $sValueKey);
     }
     return $mValue;
 }
 /**
  * @param int $level
  * @return boolean
  */
 private static function isLogLevel($level)
 {
     if (self::$minLog === FALSE) {
         if (tx_rnbase_util_Extensions::isLoaded('devlog')) {
             $minLog = tx_rnbase_configurations::getExtensionCfgValue('devlog', 'minLogLevel');
             self::$minLog = $minLog !== FALSE ? $minLog : -1;
         }
     }
     $isEnabled = $level >= self::$minLog;
     return $isEnabled;
 }
 /**
  * Is logging enabled?
  *
  * @param 	string 	$tablename
  * @return 	boolean
  */
 private static function isLog($tablename)
 {
     if (self::$log == -1) {
         // erst die Extension Konfiguration fragen!
         tx_rnbase::load('tx_rnbase_configurations');
         self::$log = intval(tx_rnbase_configurations::getExtensionCfgValue('mklib', 'logDbHandler'));
         if (self::$log) {
             tx_rnbase::load('tx_rnbase_util_Logger');
             self::$log = tx_rnbase_util_Logger::isNoticeEnabled();
         }
     }
     if (self::$log) {
         // ignore tables besorgen
         if (!is_array(self::$ignoreTables)) {
             self::$ignoreTables = t3lib_div::trimExplode(',', tx_rnbase_configurations::getExtensionCfgValue('mklib', 'logDbIgnoreTables'), true);
         }
         // tabelle loggen ?
         if (in_array($tablename, self::$ignoreTables)) {
             return false;
         }
     }
     return self::$log;
 }
예제 #5
0
<?php

if (!defined('TYPO3_MODE')) {
    die('Access denied.');
}
$rnbaseExtPath = t3lib_extMgm::extPath('rn_base');
require_once $rnbaseExtPath . 'class.tx_rnbase.php';
tx_rnbase::load('tx_rnbase_util_Debug');
tx_rnbase::load('tx_rnbase_configurations');
if (!is_array($TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['rnbase']) && tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'activateCache')) {
    $TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']['rnbase'] = array('backend' => 't3lib_cache_backend_FileBackend', 'options' => array());
}
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rn_base']['loadHiddenObjects'] = intval(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'loadHiddenObjects'));
// Include the mediaplayer service
require_once $rnbaseExtPath . 'sv1/ext_localconf.php';
 /**
  * Sendout an error mail
  * @param string $mailAddr commaseperated recipients
  * @param string $actionName
  * @param Exception $e
  * @param array $options
  */
 public static function sendErrorMail($mailAddr, $actionName, Exception $e, array $options = array())
 {
     $ignoreMailLock = array_key_exists('ignoremaillock', $options) && $options['ignoremaillock'];
     if (!$ignoreMailLock) {
         tx_rnbase::load('tx_rnbase_util_Lock');
         // Only one mail within one minute!
         $lock = tx_rnbase_util_Lock::getInstance('errormail', 60);
         if ($lock->isLocked()) {
             return;
         } else {
             $lock->lockProcess();
         }
     }
     $textPart = self::getErrorMailText($e, $actionName);
     $htmlPart = self::getErrorMailHtml($e, $actionName);
     /* @var $mail tx_rnbase_util_Mail */
     $mail = tx_rnbase::makeInstance('tx_rnbase_util_Mail');
     $mail->setSubject('Exception on site ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
     $from = tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'fromEmail');
     $from = $from ? $from : 'error@' . tx_rnbase_util_Misc::getIndpEnv('TYPO3_HOST_ONLY');
     $mail->setFrom($from);
     $mail->setTo($mailAddr);
     $mail->setTextPart($textPart);
     $mail->setHtmlPart($htmlPart);
     if ($lock && !$ignoreMailLock) {
         // refresh the lock
         $lock->lockProcess();
     }
     return $mail->send();
 }
예제 #7
0
 /**
  * Send an exeption mail for all exceptions during the store log process
  *
  * @param \Exception $e
  *
  * @TODO: add recursive call check for exceptions (
  *     throw exception, only block at secnd exception.
  *     so the gelf logger can log the exception
  *     and only a recursion of logging will prevented.
  * )
  *
  * @return void
  */
 protected function handleExceptionDuringLogging(\Exception $e)
 {
     // try to send mail
     $addr = \tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'sendEmailOnException');
     if ($addr) {
         \tx_rnbase_util_Misc::sendErrorMail($addr, 'Mklog\\DevlogLogger', $e);
     }
 }
 /**
  * Function executed from the Scheduler.
  *
  * @return boolean	Returns true on successful execution, false on error
  */
 public function execute()
 {
     /* beispiel für das logging array.
     		$devLog = array('message' => '', 'extKey' => 'mklib', 'dataVar' => FALSE);
     		$devLog = array(
     			tx_rnbase_util_Logger::LOGLEVEL_DEBUG => $devLog,
     			tx_rnbase_util_Logger::LOGLEVEL_INFO => $devLog,
     			tx_rnbase_util_Logger::LOGLEVEL_NOTICE => $devLog,
     			tx_rnbase_util_Logger::LOGLEVEL_WARN => $devLog,
     			tx_rnbase_util_Logger::LOGLEVEL_FATAL => $devLog
     		);
     		*/
     $devLog = array();
     $options = $this->getOptions();
     $startTimeInMilliseconds = t3lib_div::milliseconds();
     $memoryUsageAtStart = memory_get_usage();
     tx_rnbase_util_Logger::info('[' . get_class($this) . ']: Scheduler starts', $this->getExtKey());
     try {
         $message = $this->executeTask($options, $devLog);
         $this->setLastRunTime();
         // devlog
         if (t3lib_extMgm::isLoaded('devlog')) {
             if (empty($devLog) || isset($devLog[tx_rnbase_util_Logger::LOGLEVEL_INFO]) && empty($devLog[tx_rnbase_util_Logger::LOGLEVEL_INFO]['message'])) {
                 $devLog[tx_rnbase_util_Logger::LOGLEVEL_INFO]['message'] = $message;
             }
             foreach ($devLog as $logLevel => $logData) {
                 if (empty($logData['message'])) {
                     continue;
                 }
                 t3lib_div::devLog('[' . get_class($this) . ']: ' . $logData['message'], isset($logData['extKey']) ? $logData['extKey'] : $this->getExtKey(), $logLevel, isset($logData['dataVar']) ? $logData['dataVar'] : FALSE);
             }
         }
     } catch (Exception $exception) {
         $dataVar = array('errorcode' => $exception->getCode(), 'errormsg' => $exception->getMessage(), 'trace' => $exception->getTraceAsString(), 'options' => $options, 'devlog' => $devLog);
         if ($exception instanceof tx_rnbase_util_Exception) {
             $dataVar['exception_data'] = $exception->getAdditional(FALSE);
         }
         if (tx_rnbase_util_Logger::isFatalEnabled()) {
             tx_rnbase_util_Logger::fatal('Task [' . get_class($this) . '] failed.' . ' Error(' . $exception->getCode() . '):' . $exception->getMessage(), $this->getExtKey(), $dataVar);
         }
         // Exception Mail an die Entwicker senden
         $mail = tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'sendEmailOnException');
         if (!empty($mail)) {
             $this->sendErrorMail($mail, tx_rnbase::makeInstance('tx_rnbase_util_Exception', get_class($exception) . ': ' . $exception->getMessage(), $exception->getCode(), $dataVar, $exception));
         }
         // Wir geben die Exception weiter,
         // damit der Scheduler eine entsprechende Meldung ausgeben kann.
         throw $exception;
     }
     $memoryUsageAtEnd = memory_get_usage();
     tx_rnbase_util_Logger::info('[' . get_class($this) . ']: Scheduler ends successful ', $this->getExtKey(), array('Execution Time' => t3lib_div::milliseconds() - $startTimeInMilliseconds . ' ms', 'Memory Start' => $memoryUsageAtStart . ' Bytes', 'Memory End' => $memoryUsageAtEnd . ' Bytes', 'Memory Consumed' => $memoryUsageAtEnd - $memoryUsageAtStart . ' Bytes'));
     return true;
 }
 /**
  * Interne Verarbeitung der Exception
  * @param Exception $e
  * @param tx_rnbase_Configurations $configurations
  */
 private function handleException($actionName, Exception $e, $configurations)
 {
     $exceptionHandlerClass = tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'exceptionHandler');
     $defaultExceptionHandlerClass = 'tx_rnbase_exception_Handler';
     if (!$exceptionHandlerClass) {
         $exceptionHandlerClass = $defaultExceptionHandlerClass;
     }
     $exceptionHandler = tx_rnbase::makeInstance($exceptionHandlerClass);
     if (!$exceptionHandler instanceof tx_rnbase_exception_IHandler) {
         $exceptionHandler = tx_rnbase::makeInstance($defaultExceptionHandlerClass);
         tx_rnbase::load('tx_rnbase_util_Logger');
         tx_rnbase_util_Logger::fatal("the configured error handler ({$exceptionHandlerClass}) does not implement the tx_rnbase_exception_IHandler interface", 'rn_base');
     }
     return $exceptionHandler->handleException($actionName, $e, $configurations);
 }
 /**
  * Checks, if the debug output is anabled.
  * the given key has to match with the key from the extconf.
  *
  * @return boolean
  */
 public static function isDebugEnabled($key = NULL)
 {
     static $debugKey = NULL;
     if ($debugKey === NULL) {
         tx_rnbase::load('tx_rnbase_configurations');
         $debugKey = tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'debugKey');
     }
     if (empty($debugKey)) {
         return FALSE;
     }
     if ($key === NULL) {
         $key = $_GET['debug'];
     }
     return $debugKey === $key;
 }
 /**
  * @return mixed
  */
 protected function getExtensionCfgValue($key)
 {
     return tx_rnbase_configurations::getExtensionCfgValue($this->extKey, $key);
 }
 /**
  * Build an error message string for frontend
  * @param string $actionName
  * @param Exception $e
  * @param tx_rnbase_Configurations $configurations
  */
 protected function getErrorMessage($actionName, Exception $e, tx_rnbase_configurations $configurations)
 {
     if (tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'verboseMayday')) {
         return '<div>' . '<strong>UNCAUGHT EXCEPTION FOR VIEW: ' . $actionName . '</strong>' . '<br />CODE: ' . $e->getCode() . '<br />MESSAGE: ' . $e->getMessage() . '<br />STACK: <pre>' . $e->__toString() . '</pre>' . '</div>';
     }
     // typoscript nach fehlermeldungen prüfen
     // das machen wir nur, wenn sich diese exception nicht
     // dies kann passieren, wenn über typoscript wieder plugin angesteuert wird,
     // welches die selbe fehlermeldung produziert
     if (!$this->checkExceptionRecursion($actionName, $e, $configurations)) {
         // aktuelle meldung setzen, damit diese ggf. über ts ausgelesen werden kann (.current = 1)
         $configurations->getCObj()->setCurrentVal('ERROR ' . $e->getCode() . ': ' . $e->getMessage());
         // meldung auslesen
         $ret = $configurations->get('error.' . $e->getCode(), TRUE);
         $ret = $ret ? $ret : $configurations->get('error.default', TRUE);
     }
     // nun die sprachlabels nach einem fehler überprüfen.
     $ret = isset($ret) && $ret ? $ret : $configurations->getLL('ERROR_' . $e->getCode(), '');
     $ret = $ret ? $ret : $configurations->getLL('ERROR_default', '');
     // fallback message
     $ret = $ret ? $ret : '<div><strong>Leider ist ein unerwarteter Fehler aufgetreten.</strong></div>';
     return $ret;
 }
 /**
  * Whether or not the caching in substituteMarkerArrayCached is enabled
  * @return boolean
  */
 public static function isSubstCacheEnabled()
 {
     if (self::$substCacheEnabled === NULL) {
         self::$substCacheEnabled = (bool) tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'activateSubstCache');
     }
     return self::$substCacheEnabled;
 }
예제 #14
0
 /**
  * The global from mail address
  *
  * @return array
  */
 public function getGlobalMailFrom()
 {
     return \tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'fromEmail');
 }
 /**
  *
  * @param string $emailReceiver
  * @param array $infos
  * @param DateTime $lastRun
  * @param array $options
  *
  * @return boolean
  */
 protected function sendMail($emailReceiver, array $infos, DateTime $lastRun, array $options = array())
 {
     $contentArr = $this->buildMailContents($infos, $lastRun, $options);
     /* @var $mail tx_rnbase_util_Mail */
     $mail = tx_rnbase::makeInstance('tx_rnbase_util_Mail');
     $mail->setSubject('WatchDog for logger on site ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
     $mail->setFrom(tx_rnbase_configurations::getExtensionCfgValue('rn_base', 'fromEmail'));
     $mail->setTo($emailReceiver);
     $mail->setTextPart($contentArr['text']);
     $mail->setHtmlPart($contentArr['html']);
     return $mail->send();
 }