popHandler(); // 取出 StreamHandler 对象 * $stream_handler->setLevel(Logger::ERROR); // 重设其日志级别 * $logger->pushHandler($stream_handler); // 注册修改后的StreamHandler 对象 * $mongodb = new MongoDBHandler(new \Mongo("mongodb://***.***.***.***:27017"), "logs", "prod", Logger::INFO); * $logger->pushHandler($mongodb); // 文件 *``` * * @method static Mlogger pushHandler(HandlerInterface $handler) Pushes a handler on to the stack. * @method static Mlogger pushProcessor(callable $callback) * @method static Mlogger setHandlers(array $handlers) Set handlers, replacing all existing ones. If a map is passed, keys will be ignored. * @method static HandlerInterface popHandler() Pops a handler from the stack * @method static HandlerInterface[] getHandlers() * @method static callable popProcessor() * @method static callable[] getProcessors() * * @method static bool debug(string $message, array $context = array()) * @method static bool info(string $message, array $context = array()) * @method static bool notice(string $message, array $context = array()) * @method static bool warn(string $message, array $context = array()) * @method static bool warning(string $message, array $context = array()) * @method static bool err(string $message, array $context = array()) * @method static bool error(string $message, array $context = array()) * @method static bool crit(string $message, array $context = array()) * @method static bool critical(string $message, array $context = array()) * @method static bool alert(string $message, array $context = array()) * @method static bool emerg(string $message, array $context = array()) * @method static bool emergency(string $message, array $context = array()) * * @method static bool addRecord(string $level, $message, array $context = array()) * @method static bool addDebug(string $message, array $context = array()) * @method static bool addInfo(string $message, array $context = array()) * @method static bool addNotice(string $message, array $context = array()) * @method static bool addWarning(string $message, array $context = array()) * @method static bool addError(string $message, array $context = array()) * @method static bool addCritical(string $message, array $context = array()) * @method static bool addAlert(string $message, array $context = array()) * @method static bool addEmergency(string $message, array $context = array()) * */ class Logger { const DEBUG = 100; const INFO = 200; const NOTICE = 250; const WARNING = 300; const ERROR = 400; const CRITICAL = 500; const ALERT = 550; const EMERGENCY = 600; /** @var Mlogger */ static protected $logger; static public function init() { if (!self::$logger instanceof Mlogger) { self::$logger = new Mlogger('yunshop'); //@todo 配置日志记录目录 $handler = new StreamHandler(base_path() . '/data/logs/' . date('y_m_d') . '.log', Logger::DEBUG); $handler->getFormatter()->allowInlineLineBreaks(); $handler->getFormatter()->ignoreEmptyContextAndExtra(); self::$logger->pushProcessor(new WebProcessor()); self::$logger->pushHandler($handler); // 文件 } } static public function getLogger() { self::init(); return self::$logger; } static public function __callStatic($method, $paramters) { self::init(); if (method_exists(self::$logger, $method)) { return call_user_func_array(array(self::$logger, $method), $paramters); } if (method_exists('Mlogger', $method)) { return forward_static_call_array(array('Mlogger', $method), $paramters); } else { throw new \RuntimeException('方法不存在'); } } }