Changeset 31103
- Timestamp:
- Apr 24, 2015, 7:06:47 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/include/image.class.php
r29392 r31103 622 622 function write($destination_filepath) 623 623 { 624 global $logger; 625 624 626 $this->add_command('interlace', 'line'); // progressive rendering 625 627 // use 4:2:2 chroma subsampling (reduce file size by 20-30% with "almost" no human perception) … … 649 651 $dest = pathinfo($destination_filepath); 650 652 $exec .= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'" 2>&1'; 653 $logger->debug($exec, 'i.php'); 651 654 @exec($exec, $returnarray); 652 655 653 if (function_exists('ilog')) ilog($exec);654 656 if (is_array($returnarray) && (count($returnarray)>0) ) 655 657 { 656 if (function_exists('ilog')) ilog('ERROR', $returnarray);657 foreach ($returnarray as $line)658 $logger->error('', 'i.php', $returnarray); 659 foreach ($returnarray as $line) 658 660 trigger_error($line, E_USER_WARNING); 659 661 } -
trunk/i.php
r31102 r31103 615 615 $timing['total'] = time_step($begin); 616 616 617 if ($logger->severity() >= Logger:: INFO)618 { 619 $logger-> info('perf', 'i.php', array(617 if ($logger->severity() >= Logger::DEBUG) 618 { 619 $logger->debug('', 'i.php', array( 620 620 'src_path' => basename($page['src_path']), 621 621 'derivative_path' => basename($page['derivative_path']), -
trunk/include/Logger.class.php
r31102 r31103 96 96 private $_fileHandle = null; 97 97 98 98 99 /** 99 100 * Class constructor. … … 106 107 $this->options = array_merge($this->options, $options); 107 108 108 if (is_string($this->options['severity'])) { 109 if (is_string($this->options['severity'])) 110 { 109 111 $this->options['severity'] = self::codeToLevel($this->options['severity']); 110 112 } 111 113 112 if ($this->options['severity'] === self::OFF) { 114 if ($this->options['severity'] === self::OFF) 115 { 113 116 return; 114 117 } … … 116 119 $this->options['directory'] = rtrim($this->options['directory'], '\\/') . DIRECTORY_SEPARATOR; 117 120 118 if ($this->options['filename'] == null) { 121 if ($this->options['filename'] == null) 122 { 119 123 $this->options['filename'] = 'log_' . date('Y-m-d') . '.txt'; 120 124 } … … 122 126 $this->options['filePath'] = $this->options['directory'] . $this->options['filename']; 123 127 124 if (!file_exists($this->options['directory'])) { 125 mkgetdir($this->options['directory'], MKGETDIR_DEFAULT|MKGETDIR_PROTECT_HTACCESS); 126 } 127 128 if (file_exists($this->options['filePath']) && !is_writable($this->options['filePath'])) { 129 $this->_logStatus = self::STATUS_OPEN_FAILED; 130 throw new RuntimeException(self::$_messages['writefail']); 131 return; 132 } 133 134 if (($this->_fileHandle = fopen($this->options['filePath'], 'a'))) { 135 $this->_logStatus = self::STATUS_LOG_OPEN; 136 } 137 else { 138 $this->_logStatus = self::STATUS_OPEN_FAILED; 139 throw new RuntimeException(self::$_messages['openfail']); 140 } 141 142 if ($this->options['archiveDays'] != self::ARCHIVE_NO_PURGE && rand() % 97 == 0) { 128 if ($this->options['archiveDays'] != self::ARCHIVE_NO_PURGE && rand() % 97 == 0) 129 { 143 130 $this->purge(); 144 131 } 145 132 } 133 134 /** 135 * Open the log file if not already oppenned 136 */ 137 private function open() 138 { 139 if ($this->status() == self::STATUS_LOG_CLOSED) 140 { 141 if (!file_exists($this->options['directory'])) 142 { 143 mkgetdir($this->options['directory'], MKGETDIR_DEFAULT|MKGETDIR_PROTECT_HTACCESS); 144 } 145 146 if (file_exists($this->options['filePath']) && !is_writable($this->options['filePath'])) 147 { 148 $this->_logStatus = self::STATUS_OPEN_FAILED; 149 throw new RuntimeException(self::$_messages['writefail']); 150 return; 151 } 152 153 if (($this->_fileHandle = fopen($this->options['filePath'], 'a')) != false) 154 { 155 $this->_logStatus = self::STATUS_LOG_OPEN; 156 } 157 else 158 { 159 $this->_logStatus = self::STATUS_OPEN_FAILED; 160 throw new RuntimeException(self::$_messages['openfail']); 161 } 162 } 163 } 146 164 147 165 /** … … 150 168 public function __destruct() 151 169 { 152 if ($this->_fileHandle) { 170 if ($this->_fileHandle) 171 { 153 172 fclose($this->_fileHandle); 154 173 } … … 281 300 public function log($severity, $message, $cat = null, $args = array()) 282 301 { 283 if ($this->severity() >= $severity) { 284 if (is_array($cat)) { 302 if ($this->severity() >= $severity) 303 { 304 if (is_array($cat)) 305 { 285 306 $args = $cat; 286 307 $cat = null; … … 298 319 public function write($line) 299 320 { 300 if ($this->_logStatus == self::STATUS_LOG_OPEN) { 301 if (fwrite($this->_fileHandle, $line) === false) { 321 $this->open(); 322 if ($this->status() == self::STATUS_LOG_OPEN) 323 { 324 if (fwrite($this->_fileHandle, $line) === false) 325 { 302 326 throw new RuntimeException(self::$_messages['writefail']); 303 327 } … … 308 332 * Purges files matching 'globPattern' older than 'archiveDays'. 309 333 */ 310 public function purge() { 334 public function purge() 335 { 311 336 $files = glob($this->options['directory'] . $this->options['globPattern']); 312 337 $limit = time() - $this->options['archiveDays'] * 86400; 313 338 314 foreach ($files as $file) { 315 if (@filemtime($file) < $limit) { 339 foreach ($files as $file) 340 { 341 if (@filemtime($file) < $limit) 342 { 316 343 @unlink($file); 317 344 } … … 329 356 private function formatMessage($level, $message, $cat, $context) 330 357 { 331 if (!empty($context)) { 332 $message .= "\n" . $this->indent($this->contextToString($context)); 358 if (!empty($context)) 359 { 360 $message.= "\n" . $this->indent($this->contextToString($context)); 333 361 } 334 362 $line = "[" . $this->getTimestamp() . "]\t[" . self::levelToCode($level) . "]\t"; 335 if ($cat != null) { 336 $line .= "[" . $cat . "]\t"; 363 if ($cat != null) 364 { 365 $line.= "[" . $cat . "]\t"; 337 366 } 338 367 return $line . $message . "\n"; … … 350 379 { 351 380 $originalTime = microtime(true); 352 $micro = sprintf( "%06d", ($originalTime - floor($originalTime)) * 1000000);381 $micro = sprintf('%06d', ($originalTime - floor($originalTime)) * 1000000); 353 382 $date = new DateTime(date('Y-m-d H:i:s.'.$micro, $originalTime)); 354 383 return $date->format($this->options['dateFormat']); … … 364 393 { 365 394 $export = ''; 366 foreach ($context as $key => $value) { 367 $export .= "{$key}: "; 368 $export .= preg_replace(array( 395 foreach ($context as $key => $value) 396 { 397 $export.= $key . ': '; 398 $export.= preg_replace(array( 369 399 '/=>\s+([a-zA-Z])/im', 370 400 '/array\(\s+\)/im', 371 401 '/^ |\G /m' 372 ), array( 402 ), 403 array( 373 404 '=> $1', 374 405 'array()', 375 406 ' ' 376 ), str_replace('array (', 'array(', var_export($value, true))); 377 $export .= PHP_EOL; 407 ), 408 str_replace('array (', 'array(', var_export($value, true)) 409 ); 410 $export.= PHP_EOL; 378 411 } 379 412 return str_replace(array('\\\\', '\\\''), array('\\', '\''), rtrim($export)); … … 389 422 private function indent($string, $indent = ' ') 390 423 { 391 return $indent .str_replace("\n", "\n".$indent, $string);424 return $indent . str_replace("\n", "\n" . $indent, $string); 392 425 } 393 426 … … 400 433 static function levelToCode($level) 401 434 { 402 switch ($level) { 435 switch ($level) 436 { 403 437 case self::EMERGENCY: 404 438 return 'EMERGENCY'; … … 430 464 static function codeToLevel($code) 431 465 { 432 switch (strtoupper($code)) { 466 switch (strtoupper($code)) 467 { 433 468 case 'EMERGENCY': 434 469 return self::EMERGENCY;
Note: See TracChangeset
for help on using the changeset viewer.