日志

easySwoole提供了分类日志服务,以供记录运行信息方便调试。

  1. $log = Logger::getInstance();
  2. $log2 = Logger::getInstance('logcategory1');

log

  1. $log->log('message1');
  2. $log2->log('message2');

console

  1. $log->console("message",false);

自定义日志存储

实现LoggerWriterInterface接口

  1. namespace App\Model;
  2. use Core\AbstractInterface\LoggerWriterInterface;
  3. class Handler implements LoggerWriterInterface
  4. {
  5. static function writeLog($obj, $logCategory, $timeStamp)
  6. {
  7. // TODO: Implement writeLog() method.
  8. }
  9. }

在框架初始化后事件注入日志存储处理

  1. function frameInitialized()
  2. {
  3. // TODO: Implement frameInitialized() method.
  4. Di::getInstance()->set(SysConst::DI_LOGGER_WRITER,Handler::class);
  5. }