[李景山php]每天laravel-20160920|Writer-2

來源:互聯網
上載者:User

標籤:php

    //2016-07-20    /**     * Register a file log handler.     *     * @param  string  $path     * @param  string  $level     * @return void     */    public function useFiles($path, $level = ‘debug‘)    {        $this->monolog->pushHandler($handler = new StreamHandler($path, $this->parseLevel($level)));        $handler->setFormatter($this->getDefaultFormatter());// set formatter by get the default format    }// Register a file log handler.    /**     * Register a daily file log handler.     *     * @param  string  $path     * @param  int     $days     * @param  string  $level     * @return void     */    public function useDailyFiles($path, $days = 0, $level = ‘debug‘)    {        $this->monolog->pushHandler(            $handler = new RotatingFileHandler($path, $days, $this->parseLevel($level))        );        $handler->setFormatter($this->getDefaultFormatter());    }// a daily file file log handler    /**     * Register a Syslog handler.     *     * @param  string  $name     * @param  string  $level     * @return \Psr\Log\LoggerInterface     */    public function useSyslog($name = ‘laravel‘, $level = ‘debug‘)    {        return $this->monolog->pushHandler(new SyslogHandler($name, LOG_USER, $level));    }// get a register Sys log Handler    /**     * Register an error_log handler.     *     * @param  string  $level     * @param  int  $messageType     * @return void     */    public function useErrorLog($level = ‘debug‘, $messageType = ErrorLogHandler::OPERATING_SYSTEM)    {        $this->monolog->pushHandler(            $handler = new ErrorLogHandler($messageType, $this->parseLevel($level))        );        $handler->setFormatter($this->getDefaultFormatter());    }    /**     * Register a new callback handler for when a log event is triggered.     *     * @param  \Closure  $callback     * @return void     *     * @throws \RuntimeException     */    public function listen(Closure $callback)    {        if (! isset($this->dispatcher)) {            throw new RuntimeException(‘Events dispatcher has not been set.‘);        }        $this->dispatcher->listen(‘illuminate.log‘, $callback);    }//listen is a method   // register a new callback handler for when a log event is triggered.    /**     * Fires a log event.     *     * @param  string  $level     * @param  string  $message     * @param  array   $context     * @return void     */    protected function fireLogEvent($level, $message, array $context = [])    {        // If the event dispatcher is set, we will pass along the parameters to the        // log listeners. These are useful for building profilers or other tools        // that aggregate all of the log messages for a given "request" cycle.        if (isset($this->dispatcher)) {            $this->dispatcher->fire(‘illuminate.log‘, compact(‘level‘, ‘message‘, ‘context‘));        }// isset this->dispatcher       // dispatcher fire    }//fire like start it,more use fire log Event    /**     * Format the parameters for the logger.     *     * @param  mixed  $message     * @return mixed     */    protected function formatMessage($message)    {        if (is_array($message)) {//determine array ?            return var_export($message, true);// output        } elseif ($message instanceof Jsonable) {// a instanceof this Jsonable            return $message->toJson();//to Json        } elseif ($message instanceof Arrayable) {// instanceof Arrayable            return var_export($message->toArray(), true);// output        }        return $message;// other output message    }//format the parameters for the logger    /**     * Parse the string level into a Monolog constant.     *     * @param  string  $level     * @return int     *     * @throws \InvalidArgumentException     */    protected function parseLevel($level)    {        if (isset($this->levels[$level])) {            return $this->levels[$level];        }// isset        throw new InvalidArgumentException(‘Invalid log level.‘);//throw Exception    }// change string to int like constant.    /**     * Get the underlying Monolog instance.     *     * @return \Monolog\Logger     */    public function getMonolog()    {        return $this->monolog;    }//a big get ,magic get    /**     * Get a defaut Monolog formatter instance.     *     * @return \Monolog\Formatter\LineFormatter     */    protected function getDefaultFormatter()    {        return new LineFormatter(null, null, true, true);    }// a default format is a line Format    /**     * Get the event dispatcher instance.     *     * @return \Illuminate\Contracts\Events\Dispatcher     */    public function getEventDispatcher()    {        return $this->dispatcher;    }//get dispatcher    /**     * Set the event dispatcher instance.     *     * @param  \Illuminate\Contracts\Events\Dispatcher  $dispatcher     * @return void     */    public function setEventDispatcher(Dispatcher $dispatcher)    {        $this->dispatcher = $dispatcher;    }// set the dispatcher.}


本文出自 “專註php” 部落格,請務必保留此出處http://jingshanls.blog.51cto.com/3357095/1828259

[李景山php]每天laravel-20160920|Writer-2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.