[李景山php]每天laravel-20160919|Writer-1
2016-07-20 09:06
525 查看
<?php namespace 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 this class 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
- [李景山php]每天laravel-20160918|HashServerProvider
- [李景山php]每天laravel-20160918|HashServerProvider
- PHP简单日历实现方法
- deepin安装vsftpd(仅配置篇--续--虚拟用户篇)
- coreseek+php之sphinx扩展安装+php调用示例
- Windows 2008 利用Filezilla server搭建FTP
- 在 Laravel 中使用 Laravel Searchy 扩展包实现基于数据库的轻量级搜索功能
- php-迭代创建级联目录
- PHP简单日历实现方法
- php实现登录tplink WR882N获取IP和重启的方法
- PHP二维数组矩形转置实例
- 支付宝服务窗API接口开发php版本
- php图片添加水印例子
- php验证身份证号码正确性的函数
- Zend Framework教程之Zend_Helpers动作助手ViewRenderer用法详解
- PHP实现的随机IP函数【国内IP段】
- php+ajax注册实时验证功能
- PHP+Ajax实现验证码的实时验证
- PHP+Ajax验证码验证用户登录