<?php

namespace App\Log;

use Monolog\Handler\AbstractProcessingHandler;
use App\Notification\DingDingRobot;
use Monolog\Logger;

class DingDingHandler extends AbstractProcessingHandler
{
    /**
     * @var DingDingRobot
     */
    protected $dingDingRobot;

    public function __construct(DingDingRobot $dingDingRobot, $level = Logger::DEBUG, $bubble = true)
    {
        parent::__construct($level, $bubble);
        $this->dingDingRobot = $dingDingRobot;
    }

    /**
     * Writes the record down to the log of the implementing handler
     *
     * @param array $record
     * @return void
     */
    protected function write(array $record)
    {
        $this->dingDingRobot->markdown(
            env('APP_ENV').'ERROR级别日志',
            "## [ERROR级别日志]\n{$record['formatted']}"
        );
    }
}
