コード例 #1
0
<?php

namespace Components;

Log::push(new Log_Appender_Syslog(COMPONENTS_APP_CODE));
if (Environment::isDev()) {
    Runtime::addManagementIp(Runtime::getClientAddress());
}
if (isset($_REQUEST['debug']) || Environment::isDev()) {
    if (isset($_REQUEST['debug'])) {
        $debug = (int) $_REQUEST['debug'];
    } else {
        $debug = Debug::INFO;
    }
    if (0 < $debug) {
        Debug::activate();
    }
    Debug::verbosity($debug);
    Debug::appender(Debug::INFO, new Debug_Appender_Console());
    Debug::enable(Debug::MARKUP);
}
コード例 #2
0
 protected function compilePattern()
 {
     $available = ['l' => function () {
         return $this->__level;
     }, 'L' => function () {
         return self::$m_mapLevelToOutput[$this->__level];
     }, 'd' => function () {
         return microtime(true);
     }, 'D' => function () {
         $microtime = (string) microtime(true);
         return date($this->patternDate, $microtime) . substr($microtime, strpos($microtime, '.'));
     }, 'b' => function () {
         return memory_get_usage(true);
     }, 'B' => function () {
         return \io\convertToMB(memory_get_usage(true)) . ' MB';
     }, 'm' => function () {
         return $this->__message;
     }, 'n' => function () {
         return $this->__namespace;
     }];
     $clientIp = Runtime::getClientAddress();
     if (!($clientIpLong = ip2long($clientIp))) {
         $clientIpLong = 0;
     }
     $requestUri = '/';
     if (isset($_SERVER['REQUEST_URI'])) {
         $requestUri = $_SERVER['REQUEST_URI'];
     } else {
         if (isset($argv) && 0 < $argc) {
             $requestUri = http_build_query($argv);
         }
     }
     $this->m_patternCompiled = \str\replace($this->pattern, ['%h', '%c', '%C', '%r'], [$this->host, $clientIpLong, $clientIp, $requestUri]);
     $chars = \str\split($this->pattern, 1);
     $count = count($chars);
     $placeholders = '';
     $callbacks = [];
     for ($idx = 0; $idx < $count; $idx++) {
         if ('%' == $chars[$idx] && ++$idx < $count) {
             $placeholder = $chars[$idx];
             if (isset($available[$placeholder])) {
                 $placeholders .= $placeholder;
                 $callbacks["%{$placeholder}"] = $available[$placeholder];
             }
         }
     }
     $this->m_patternPlaceholder = "/(%[{$placeholders}])+/";
     $this->m_patternCallbacks = $callbacks;
 }