loggerpatternparser.php.svn-base

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 409 行 · 第 1/2 页

SVN-BASE
409
字号
                                // LoggerLog::debug("LoggerPatternParser::parse() next char is an escape char");                                                    $this->currentLiteral .= $c;                                $this->i++; // move pointer                                break;                            case 'n':                                // LoggerLog::debug("LoggerPatternParser::parse() next char is 'n'");                                                            $this->currentLiteral .= LOG4PHP_LINE_SEP;                                $this->i++; // move pointer                                break;                            default:                                if(strlen($this->currentLiteral) != 0) {                                    $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral));                                    LoggerLog::debug("LoggerPatternParser::parse() Parsed LITERAL converter: \"{$this->currentLiteral}\".");                                }                                $this->currentLiteral = $c;                                $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE;                                $this->formattingInfo->reset();                        }                    } else {                        $this->currentLiteral .= $c;                    }                    break;              case LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE:                    // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_CONVERTER_STATE'");                                      $this->currentLiteral .= $c;                        switch($c) {                        case '-':                            $this->formattingInfo->leftAlign = true;                            break;                        case '.':                            $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE;                                break;                        default:                            if(ord($c) >= ord('0') and ord($c) <= ord('9')) {                                    $this->formattingInfo->min = ord($c) - ord('0');                                    $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE;                            } else {                                $this->finalizeConverter($c);                            }                        } // switch                    break;              case LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE:                    // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_MIN_STATE'");                                      $this->currentLiteral .= $c;                    if(ord($c) >= ord('0') and ord($c) <= ord('9')) {                        $this->formattingInfo->min = ($this->formattingInfo->min * 10) + (ord($c) - ord('0'));                        } elseif ($c == '.') {                        $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE;                    } else {                        $this->finalizeConverter($c);                        }                        break;              case LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE:                    // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_DOT_STATE'");                                      $this->currentLiteral .= $c;                    if(ord($c) >= ord('0') and ord($c) <= ord('9')) {                        $this->formattingInfo->max = ord($c) - ord('0');                            $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE;                    } else {                          LoggerLog::warn("LoggerPatternParser::parse() Error occured in position {$this->i}. Was expecting digit, instead got char \"{$c}\".");                          $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE;                    }                        break;              case LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE:                    // LoggerLog::debug("LoggerPatternParser::parse() state is 'LOG4PHP_LOGGER_PATTERN_PARSER_MAX_STATE'");                                      $this->currentLiteral .= $c;                    if(ord($c) >= ord('0') and ord($c) <= ord('9')) {                        $this->formattingInfo->max = ($this->formattingInfo->max * 10) + (ord($c) - ord('0'));                        } else {                          $this->finalizeConverter($c);                      $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE;                        }                        break;            } // switch        } // while        if(strlen($this->currentLiteral) != 0) {            $this->addToList(new LoggerLiteralPatternConverter($this->currentLiteral));            // LoggerLog::debug("LoggerPatternParser::parse() Parsed LITERAL converter: \"{$this->currentLiteral}\".");        }        return $this->head;    }    function finalizeConverter($c)    {        LoggerLog::debug("LoggerPatternParser::finalizeConverter() with char '$c'");            $pc = null;        switch($c) {            case 'c':                $pc = new LoggerCategoryPatternConverter($this->formattingInfo, $this->extractPrecisionOption());                LoggerLog::debug("LoggerPatternParser::finalizeConverter() CATEGORY converter.");                $this->currentLiteral = '';                break;            case 'C':                $pc = new LoggerClassNamePatternConverter($this->formattingInfo, $this->extractPrecisionOption());                LoggerLog::debug("LoggerPatternParser::finalizeConverter() CLASSNAME converter.");                $this->currentLiteral = '';                break;            case 'd':                $dateFormatStr = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601; // ISO8601_DATE_FORMAT;                $dOpt = $this->extractOption();                if($dOpt !== null)                        $dateFormatStr = $dOpt;                                    if ($dateFormatStr == 'ISO8601') {                    $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601;                } elseif($dateFormatStr == 'ABSOLUTE') {                    $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ABSOLUTE;                } elseif($dateFormatStr == 'DATE') {                    $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_DATE;                } else {                    $df = $dateFormatStr;                    if ($df == null) {                        $df = LOG4PHP_LOGGER_PATTERN_PARSER_DATE_FORMAT_ISO8601;                    }                    }                $pc = new LoggerDatePatternConverter($this->formattingInfo, $df);                $this->currentLiteral = '';                break;            case 'F':                $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_FILE_LOCATION_CONVERTER);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() File name converter.");                $this->currentLiteral = '';                break;            case 'l':                $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_FULL_LOCATION_CONVERTER);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() Location converter.");                $this->currentLiteral = '';                break;            case 'L':                $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LINE_LOCATION_CONVERTER);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() LINE NUMBER converter.");                $this->currentLiteral = '';                break;            case 'm':                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_MESSAGE_CONVERTER);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() MESSAGE converter.");                $this->currentLiteral = '';                break;            case 'M':                $pc = new LoggerLocationPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_METHOD_LOCATION_CONVERTER);                $this->currentLiteral = '';                break;            case 'p':                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_LEVEL_CONVERTER);                $this->currentLiteral = '';                break;            case 'r':                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_RELATIVE_TIME_CONVERTER);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() RELATIVE TIME converter.");                $this->currentLiteral = '';                break;            case 't':                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_THREAD_CONVERTER);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() THREAD converter.");                $this->currentLiteral = '';                break;            case 'u':                if($this->i < $this->patternLength) {                        $cNext = $this->pattern{$this->i};                    if(ord($cNext) >= ord('0') and ord($cNext) <= ord('9')) {                            $pc = new LoggerUserFieldPatternConverter($this->formattingInfo, (string)(ord($cNext) - ord('0')));                        LoggerLog::debug("LoggerPatternParser::finalizeConverter() USER converter [{$cNext}].");                        $this->currentLiteral = '';                            $this->i++;                        } else {                        LoggerLog::warn("LoggerPatternParser::finalizeConverter() Unexpected char '{$cNext}' at position {$this->i}.");                    }                }                break;            case 'x':                $pc = new LoggerBasicPatternConverter($this->formattingInfo, LOG4PHP_LOGGER_PATTERN_PARSER_NDC_CONVERTER);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() NDC converter.");                $this->currentLiteral = '';                break;            case 'X':                $xOpt = $this->extractOption();                $pc = new LoggerMDCPatternConverter($this->formattingInfo, $xOpt);                LoggerLog::debug("LoggerPatternParser::finalizeConverter() MDC converter.");                $this->currentLiteral = '';                break;            default:                LoggerLog::warn("LoggerPatternParser::finalizeConverter() Unexpected char [$c] at position {$this->i} in conversion pattern.");                $pc = new LoggerLiteralPatternConverter($this->currentLiteral);                $this->currentLiteral = '';        }        $this->addConverter($pc);    }    function addConverter($pc)    {        $this->currentLiteral = '';        // Add the pattern converter to the list.        $this->addToList($pc);        // Next pattern is assumed to be a literal.        $this->state = LOG4PHP_LOGGER_PATTERN_PARSER_LITERAL_STATE;        // Reset formatting info        $this->formattingInfo->reset();    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?