[李景山php]每天laravel-20160919|Writer-1

來源:互聯網
上載者:User

標籤:php

<?phpnamespace Illuminate\Log;use Closure;use RuntimeException;use InvalidArgumentException;use Monolog\Handler\SyslogHandler;use Monolog\Handler\StreamHandler;use Monolog\Logger as MonologLogger;use Monolog\Formatter\LineFormatter;use Monolog\Handler\ErrorLogHandler;use Monolog\Handler\RotatingFileHandler;use Illuminate\Contracts\Support\Jsonable;use Illuminate\Contracts\Events\Dispatcher;use Illuminate\Contracts\Support\Arrayable;use Psr\Log\LoggerInterface as PsrLoggerInterface;use Illuminate\Contracts\Logging\Log as LogContract;// more namespace use as thisclass Writer implements LogContract, PsrLoggerInterface{// class writer implements LogContract, and PsrLoggerInterface    /**     * The Monolog logger instance.     *     * @var \Monolog\Logger     */    protected $monolog;// The Monolog logger instance. a    /**     * The event dispatcher instance.     *     * @var \Illuminate\Contracts\Events\Dispatcher     */    protected $dispatcher;//The event dispatcher instance.   // a instance about this dispatcher    /**     * The Log levels.     *     * @var array     */    protected $levels = [        ‘debug‘     => MonologLogger::DEBUG,        ‘info‘      => MonologLogger::INFO,        ‘notice‘    => MonologLogger::NOTICE,        ‘warning‘   => MonologLogger::WARNING,        ‘error‘     => MonologLogger::ERROR,        ‘critical‘  => MonologLogger::CRITICAL,        ‘alert‘     => MonologLogger::ALERT,        ‘emergency‘ => MonologLogger::EMERGENCY,    ];// a log levels ,use a log    /**     * Create a new log writer instance.     *     * @param  \Monolog\Logger  $monolog     * @param  \Illuminate\Contracts\Events\Dispatcher  $dispatcher     * @return void     */    public function __construct(MonologLogger $monolog, Dispatcher $dispatcher = null)    {        $this->monolog = $monolog;// set this monolog, set dispatcher        if (isset($dispatcher)) {// determine this dispatcher            $this->dispatcher = $dispatcher;// set this dispatcher        }    }//Create a new log writer instance.    /**     * Log an emergency message to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function emergency($message, array $context = [])    {// write log        return $this->writeLog(__FUNCTION__, $message, $context);    }//Log an emergency message to the logs. use function name message and context    /**     * Log an alert message to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function alert($message, array $context = [])    {        return $this->writeLog(__FUNCTION__, $message, $context);    }// ditto    /**     * Log a critical message to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function critical($message, array $context = [])    {        return $this->writeLog(__FUNCTION__, $message, $context);    }//ditto    /**     * Log an error message to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function error($message, array $context = [])    {        return $this->writeLog(__FUNCTION__, $message, $context);    }//ditto    /**     * Log a warning message to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function warning($message, array $context = [])    {        return $this->writeLog(__FUNCTION__, $message, $context);    }//ditto    /**     * Log a notice to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function notice($message, array $context = [])    {        return $this->writeLog(__FUNCTION__, $message, $context);    }//ditto    /**     * Log an informational message to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function info($message, array $context = [])    {        return $this->writeLog(__FUNCTION__, $message, $context);    }//ditto    /**     * Log a debug message to the logs.     *     * @param  string  $message     * @param  array  $context     * @return void     */    public function debug($message, array $context = [])    {        return $this->writeLog(__FUNCTION__, $message, $context);    }//ditto    /**     * Log a message to the logs.     *     * @param  string  $level     * @param  string  $message     * @param  array  $context     * @return void     */    public function log($level, $message, array $context = [])    {        return $this->writeLog($level, $message, $context);    }//ditto    /**     * Dynamically pass log calls into the writer.     *     * @param  string  $level     * @param  string  $message     * @param  array  $context     * @return void     */    public function write($level, $message, array $context = [])    {        return $this->writeLog($level, $message, $context);    }//ditto    /**     * Write a message to Monolog.     *     * @param  string  $level     * @param  string  $message     * @param  array  $context     * @return void     */    protected function writeLog($level, $message, $context)    {        $this->fireLogEvent($level, $message = $this->formatMessage($message), $context);       // start event ,like fire Log Event with levels message and context       // get a right message format        $this->monolog->{$level}($message, $context);//use this self function    }


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

[李景山php]每天laravel-20160919|Writer-1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.