-
+ 9CE033526D4B872FA20141A90DF8CB571059E4196A0698BAB5F9CE11725B2D8FC03192EFF3B979F9B11FAF660A3929A5A7573A929393974022634131B0EE2BA5
mp-wp/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php
(0 . 0)(1 . 267)
123544 <?php
123545 /**
123546 * $Id: Logger.class.php 10 2007-05-27 10:55:12Z spocke $
123547 *
123548 * @package MCFileManager.filesystems
123549 * @author Moxiecode
123550 */
123551
123552 // File type contstants
123553 define('MC_LOGGER_DEBUG', 0);
123554 define('MC_LOGGER_INFO', 10);
123555 define('MC_LOGGER_WARN', 20);
123556 define('MC_LOGGER_ERROR', 30);
123557 define('MC_LOGGER_FATAL', 40);
123558
123559 /**
123560 * Logging utility class. This class handles basic logging with levels, log rotation and custom log formats. It's
123561 * designed to be compact but still powerful and flexible.
123562 */
123563 class Moxiecode_Logger {
123564 // Private fields
123565 var $_path;
123566 var $_filename;
123567 var $_maxSize;
123568 var $_maxFiles;
123569 var $_maxSizeBytes;
123570 var $_level;
123571 var $_format;
123572
123573 /**
123574 * Constructs a new logger instance.
123575 */
123576 function Moxiecode_Logger() {
123577 $this->_path = "";
123578 $this->_filename = "{level}.log";
123579 $this->setMaxSize("100k");
123580 $this->_maxFiles = 10;
123581 $this->_level = MC_LOGGER_DEBUG;
123582 $this->_format = "[{time}] [{level}] {message}";
123583 }
123584
123585 /**
123586 * Sets the current log level, use the MC_LOGGER constants.
123587 *
123588 * @param int $level Log level instance for example MC_LOGGER_DEBUG.
123589 */
123590 function setLevel($level) {
123591 if (is_string($level)) {
123592 switch (strtolower($level)) {
123593 case "debug":
123594 $level = MC_LOGGER_DEBUG;
123595 break;
123596
123597 case "info":
123598 $level = MC_LOGGER_INFO;
123599 break;
123600
123601 case "warn":
123602 case "warning":
123603 $level = MC_LOGGER_WARN;
123604 break;
123605
123606 case "error":
123607 $level = MC_LOGGER_ERROR;
123608 break;
123609
123610 case "fatal":
123611 $level = MC_LOGGER_FATAL;
123612 break;
123613
123614 default:
123615 $level = MC_LOGGER_FATAL;
123616 }
123617 }
123618
123619 $this->_level = $level;
123620 }
123621
123622 /**
123623 * Returns the current log level for example MC_LOGGER_DEBUG.
123624 *
123625 * @return int Current log level for example MC_LOGGER_DEBUG.
123626 */
123627 function getLevel() {
123628 return $this->_level;
123629 }
123630
123631 function setPath($path) {
123632 $this->_path = $path;
123633 }
123634
123635 function getPath() {
123636 return $this->_path;
123637 }
123638
123639 function setFileName($file_name) {
123640 $this->_filename = $file_name;
123641 }
123642
123643 function getFileName() {
123644 return $this->_filename;
123645 }
123646
123647 function setFormat($format) {
123648 $this->_format = $format;
123649 }
123650
123651 function getFormat() {
123652 return $this->_format;
123653 }
123654
123655 function setMaxSize($size) {
123656 // Fix log max size
123657 $logMaxSizeBytes = intval(preg_replace("/[^0-9]/", "", $size));
123658
123659 // Is KB
123660 if (strpos((strtolower($size)), "k") > 0)
123661 $logMaxSizeBytes *= 1024;
123662
123663 // Is MB
123664 if (strpos((strtolower($size)), "m") > 0)
123665 $logMaxSizeBytes *= (1024 * 1024);
123666
123667 $this->_maxSizeBytes = $logMaxSizeBytes;
123668 $this->_maxSize = $size;
123669 }
123670
123671 function getMaxSize() {
123672 return $this->_maxSize;
123673 }
123674
123675 function setMaxFiles($max_files) {
123676 $this->_maxFiles = $max_files;
123677 }
123678
123679 function getMaxFiles() {
123680 return $this->_maxFiles;
123681 }
123682
123683 function debug($msg) {
123684 $args = func_get_args();
123685 $this->_logMsg(MC_LOGGER_DEBUG, implode(', ', $args));
123686 }
123687
123688 function info($msg) {
123689 $args = func_get_args();
123690 $this->_logMsg(MC_LOGGER_INFO, implode(', ', $args));
123691 }
123692
123693 function warn($msg) {
123694 $args = func_get_args();
123695 $this->_logMsg(MC_LOGGER_WARN, implode(', ', $args));
123696 }
123697
123698 function error($msg) {
123699 $args = func_get_args();
123700 $this->_logMsg(MC_LOGGER_ERROR, implode(', ', $args));
123701 }
123702
123703 function fatal($msg) {
123704 $args = func_get_args();
123705 $this->_logMsg(MC_LOGGER_FATAL, implode(', ', $args));
123706 }
123707
123708 function isDebugEnabled() {
123709 return $this->_level >= MC_LOGGER_DEBUG;
123710 }
123711
123712 function isInfoEnabled() {
123713 return $this->_level >= MC_LOGGER_INFO;
123714 }
123715
123716 function isWarnEnabled() {
123717 return $this->_level >= MC_LOGGER_WARN;
123718 }
123719
123720 function isErrorEnabled() {
123721 return $this->_level >= MC_LOGGER_ERROR;
123722 }
123723
123724 function isFatalEnabled() {
123725 return $this->_level >= MC_LOGGER_FATAL;
123726 }
123727
123728 function _logMsg($level, $message) {
123729 $roll = false;
123730
123731 if ($level < $this->_level)
123732 return;
123733
123734 $logFile = $this->toOSPath($this->_path . "/" . $this->_filename);
123735
123736 switch ($level) {
123737 case MC_LOGGER_DEBUG:
123738 $levelName = "DEBUG";
123739 break;
123740
123741 case MC_LOGGER_INFO:
123742 $levelName = "INFO";
123743 break;
123744
123745 case MC_LOGGER_WARN:
123746 $levelName = "WARN";
123747 break;
123748
123749 case MC_LOGGER_ERROR:
123750 $levelName = "ERROR";
123751 break;
123752
123753 case MC_LOGGER_FATAL:
123754 $levelName = "FATAL";
123755 break;
123756 }
123757
123758 $logFile = str_replace('{level}', strtolower($levelName), $logFile);
123759
123760 $text = $this->_format;
123761 $text = str_replace('{time}', date("Y-m-d H:i:s"), $text);
123762 $text = str_replace('{level}', strtolower($levelName), $text);
123763 $text = str_replace('{message}', $message, $text);
123764 $message = $text . "\r\n";
123765
123766 // Check filesize
123767 if (file_exists($logFile)) {
123768 $size = @filesize($logFile);
123769
123770 if ($size + strlen($message) > $this->_maxSizeBytes)
123771 $roll = true;
123772 }
123773
123774 // Roll if the size is right
123775 if ($roll) {
123776 for ($i=$this->_maxFiles-1; $i>=1; $i--) {
123777 $rfile = $this->toOSPath($logFile . "." . $i);
123778 $nfile = $this->toOSPath($logFile . "." . ($i+1));
123779
123780 if (@file_exists($rfile))
123781 @rename($rfile, $nfile);
123782 }
123783
123784 @rename($logFile, $this->toOSPath($logFile . ".1"));
123785
123786 // Delete last logfile
123787 $delfile = $this->toOSPath($logFile . "." . ($this->_maxFiles + 1));
123788 if (@file_exists($delfile))
123789 @unlink($delfile);
123790 }
123791
123792 // Append log line
123793 if (($fp = @fopen($logFile, "a")) != null) {
123794 @fputs($fp, $message);
123795 @fflush($fp);
123796 @fclose($fp);
123797 }
123798 }
123799
123800 /**
123801 * Converts a Unix path to OS specific path.
123802 *
123803 * @param String $path Unix path to convert.
123804 */
123805 function toOSPath($path) {
123806 return str_replace("/", DIRECTORY_SEPARATOR, $path);
123807 }
123808 }
123809
123810 ?>