lumen/laravel 毫秒时间戳日志

1.修改 bootstrap/app.php

$app->configureMonologUsing(function(Monolog\Logger $monolog) use ($app) {

   return $monolog->pushHandler( new \App\Handler\MonoLogFormatLineHandler($app->storagePath().'/logs/lumen.log') );

});

2.创建文件app/Handle/MonoLogFormatLineHandler.php

namespace App\Handler;

/**

* Created by PhpStorm.

* User: xiaojun

* Date: 18-5-19

* Time: 下午6:04

*/

use Monolog\Handler\RotatingFileHandler;

use Monolog\Handler\HandlerInterface;

use Monolog\Formatter\LineFormatter;

class MonoLogFormatLineHandler extends RotatingFileHandler implements HandlerInterface {

    const MICROTIME = 'Y-m-d H:i:s.u';

    public function __construct($filename){

      parent::__construct($filename);

}

    public function handle(array $record)

{

        if (!$this->isHandling($record)) {

            return false;

}

        $record = $this->processRecord($record);

        $this->setFormatter(new LineFormatter(null, self::MICROTIME));

        $record['formatted'] = $this->getFormatter()->format($record);

        $this->write($record);

        return false === $this->bubble;

}

}

3.日志样式

[2018-05-20 03:13:13.417198] lumen.INFO: RESPONSE>>> {"_o_status":200,"_o_content":null,"curResponse":{"_o_requestid":"c762bd3d-8288-4ea8-bbf1-03245dafac05","_o_time":"2018-05-20-03:13:13"}} []

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 2,045评论 0 2
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,841评论 18 139
  • 先说几句废话,调和气氛。事情的起由来自客户需求频繁变更,伟大的师傅决定横刀立马的改革使用新的框架(created ...
    wsdadan阅读 3,076评论 0 12
  • 前言 前几天在GitHub看到一篇写PHP简洁之道的译文,觉得还不错,所以转在了自己的博客中,只不过有一些地方好像...
    guanguans阅读 610评论 3 6
  • 感觉自己参加了一个比高考还高考的考试,每次常识做错很多的时候就想着自己当初高考的时候可是什么都知道的呢。做题听课很...
    沫晞阅读 299评论 0 0