Beispiel #1
0
                self::loadOneConfig(array('name' => 'default', 'isLogging' => true, 'basePath' => self::$g_basePath, 'mode' => self::LOG_MODE_FILE, 'level' => self::LOG_LEVEL_DEBUG, 'frequency' => self::LOG_FREQUENCY_NONE));
            }
            // 删除已有的logger对象
            if (isset(self::$logPool[$name])) {
                unset(self::$logPool[$name]);
            }
            // 检测配置文件是否加载
            if (!isset(self::$g_config_arr[$name])) {
                throw new TLoggerException("Make sure that the log configuration which name is '{$name}' is loaded successfully");
            }
            // 根据配置文件实例化logger,并保存到logger单例数组中
            $config = self::$g_config_arr[$name];
            $reflector = new ReflectionClass($config['handleClass']);
            $logger = $reflector->newInstance($config);
            self::$logPool[$name] = $logger;
        }
        return self::$logPool[$name];
    }
}
//测试
if (strtolower(PHP_SAPI) == 'cli' && isset($argv) && basename(__FILE__) == basename($argv[0])) {
    $config = array('name' => 'test', 'level' => TLogger::LOG_LEVEL_INFO, 'frequency' => TLogger::LOG_FREQUENCY_MINUTE);
    TLogger::$g_basePath = __DIR__ . DIRECTORY_SEPARATOR . 'log';
    TLogger::loadOneConfig($config);
    $logger = TLogger::getLogger("test");
    $logger->debug("this is debug info ");
    $logger->info(array("is", "info", "recode"));
    $logger->warn(21);
    $logger->error("error info ");
    $logger->fatal($logger);
}