[Li Jingshan php] every day laravel-20160920| Writer-2

Source: Internet
Author: User

    //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.}


This article is from the "Focus on PHP" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1828259

[Li Jingshan php] every day laravel-20160920| Writer-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.