admin/app/framework/Log/BaseLog.php

45 lines
1.0 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: shenyang
* Date: 2018/11/20
* Time: 3:32 PM
*/
namespace app\framework\Log;
use app\common\facades\SiteSetting;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Illuminate\Log\Writer;
abstract class BaseLog
{
protected $logDir = '';
protected $days = 7;
/**
* @var Writer;
*/
protected $log;
public function __construct()
{
try {
$this->days = intval(SiteSetting::get('website_log')['day']) ?: 7;
} catch (\Exception $e) {
}
$this->log = new \Illuminate\Log\Logger(new Logger(config('app.env')));
$this->log->getLogger()->pushHandler(
$handler = new RotatingFileHandler(storage_path() . '/' . $this->logDir, $this->days)
);
$handler->setFormatter(new LineFormatter(null, null, true, true));
}
abstract public function add($message, array $content = []);
public function getLogger()
{
return $this->log;
}
}