Ejemplo n.º 1
0
 /**
  * Sends to the logging subsystem the perf data in $values.
  * - checking first if there is any logging filter class registered
  * - removing from $values all variables not defined in ezperformancelogger.ini/TrackVars
  *
  * @too !important split method in 2 methods, with one public and one protected?
  */
 protected static function logIfNeeded(array $values, &$output)
 {
     // check if there is any registered filter class. If there is, ask it whether we should log or not
     $skip = false;
     $filters = eZPerfLoggerINI::variable('GeneralSettings', 'LogFilters');
     // cater to 'array reset' situations: only 1 empty val in the array
     if (count($filters) > 1 || count($filters) == 1 && $filters[0] != '') {
         $skip = true;
         foreach ($filters as $filterClass) {
             if (call_user_func_array(array($filterClass, 'shouldLog'), array($values, $output))) {
                 $skip = false;
                 break;
             }
         }
     }
     if (!$skip) {
         // build the array with the values we want to record in the logs -
         // only the ones corresponding to variables defined in the ini file,
         // not all the values measured so far
         $toLog = array();
         foreach (eZPerfLoggerINI::variable('GeneralSettings', 'TrackVariables') as $varName) {
             $toLog[$varName] = isset($values[$varName]) ? $values[$varName] : null;
         }
         // for each logging type configured, log values to it, using the class which supports it
         foreach (eZPerfLoggerINI::variable('GeneralSettings', 'LogMethods') as $logMethod) {
             $logged = false;
             foreach (eZPerfLoggerINI::variable('GeneralSettings', 'LogProviders') as $loggerClass) {
                 /// @todo !important check that $loggerClass exposes the correct interface
                 if (in_array($logMethod, call_user_func(array($loggerClass, 'supportedLogMethods')))) {
                     call_user_func_array(array($loggerClass, 'doLog'), array($logMethod, $toLog, &$output));
                     $logged = true;
                     break;
                 }
             }
             if (!$logged) {
                 eZPerfLoggerDebug::writeError("Could not log perf data to log '{$logMethod}', no logger class supports it", __METHOD__);
             }
         }
     }
 }
 /**
  * Writes a "token file"
  * This is useful whenever there are log files which get parse based on cronjobs
  * and we have to remember the last line which has been found
  */
 protected static function writeUpdateToken($tokenFile, $tokenLine)
 {
     $sys = eZSys::instance();
     $updateViewLogPath = $sys->varDirectory() . "/" . eZPerfLoggerINI::variable('FileSettings', 'LogDir', 'site.ini') . "/" . $tokenFile;
     $dt = new eZDateTime();
     if (!file_put_contents($updateViewLogPath, "# Finished at " . $dt->toString() . "\n" . "# Last updated entry:" . "\n" . $tokenLine . "\n")) {
         eZPerfLoggerDebug::writeError("Could not store last date of perf-log file parsing in {$updateViewLogPath}, double-counting might occur", __METHOD__);
     }
 }