Esempio n. 1
0
 /**
  * Saves log messages in files.
  *
  * @param array $logs list of log messages
  */
 protected function processLogs($logs)
 {
     $logFile = IOHelper::normalizePathSeparators($this->getLogPath() . '/' . $this->getLogFile());
     if (IOHelper::getFileSize($logFile) > $this->getMaxFileSize() * 1024) {
         $this->rotateFiles();
     }
     $lock = craft()->config->get('useLockWhenWritingToFile') === true;
     $fp = @fopen($logFile, 'a');
     if ($lock) {
         @flock($fp, LOCK_EX);
     }
     foreach ($logs as $log) {
         $message = LoggingHelper::redact($log[0]);
         $level = $log[1];
         $category = $log[2];
         $time = $log[3];
         $force = isset($log[4]) && $log[4] == true ? true : false;
         @fwrite($fp, $this->formatLogMessageWithForce($message, $level, $category, $time, $force));
     }
     @fwrite($fp, PHP_EOL . '******************************************************************************************************' . PHP_EOL);
     if ($lock) {
         @flock($fp, LOCK_UN);
     }
     @fclose($fp);
 }
Esempio n. 2
0
 /**
  * Saves log messages in files.
  *
  * @param array $logs The list of log messages
  *
  * @return null
  */
 protected function processLogs($logs)
 {
     $types = array();
     foreach ($logs as $log) {
         $message = LoggingHelper::redact($log[0]);
         $level = $log[1];
         $category = $log[2];
         $time = $log[3];
         $force = isset($log[4]) && $log[4] == true ? true : false;
         $plugin = isset($log[5]) ? StringHelper::toLowerCase($log[5]) : 'craft';
         if (isset($types[$plugin])) {
             $types[$plugin] .= $this->formatLogMessageWithForce($message, $level, $category, $time, $force, $plugin);
         } else {
             $types[$plugin] = $this->formatLogMessageWithForce($message, $level, $category, $time, $force, $plugin);
         }
     }
     foreach ($types as $plugin => $text) {
         $text .= PHP_EOL . '******************************************************************************************************' . PHP_EOL;
         $this->setLogFile($plugin . '.log');
         $logFile = IOHelper::normalizePathSeparators($this->getLogPath() . '/' . $this->getLogFile());
         // Check the config setting first.  Is it set to true?
         if (craft()->config->get('useWriteFileLock') === true) {
             $lock = true;
         } else {
             if (craft()->config->get('useWriteFileLock') === false) {
                 $lock = false;
             } else {
                 if (craft()->cache->get('useWriteFileLock') === 'yes') {
                     $lock = true;
                 } else {
                     $lock = false;
                 }
             }
         }
         $fp = @fopen($logFile, 'a');
         if ($lock) {
             @flock($fp, LOCK_EX);
         }
         if (IOHelper::getFileSize($logFile) > $this->getMaxFileSize() * 1024) {
             $this->rotateFiles();
             if ($lock) {
                 @flock($fp, LOCK_UN);
             }
             @fclose($fp);
             if ($lock) {
                 IOHelper::writeToFile($logFile, $text, false, true, false);
             } else {
                 IOHelper::writeToFile($logFile, $text, false, true, true);
             }
         } else {
             @fwrite($fp, $text);
             if ($lock) {
                 @flock($fp, LOCK_UN);
             }
             @fclose($fp);
         }
     }
 }
Esempio n. 3
0
 public function __construct()
 {
     $this->log = LoggingHelper::getLogger();
 }
Esempio n. 4
0
 function __construct()
 {
     $this->pdo = Conexion::getInstance();
     $this->log = LoggingHelper::getLogger();
 }