【发布时间】:2016-12-30 19:19:46
【问题描述】:
我需要覆盖使用 Laravel 5.3 制作的项目的格式日志
我使用 post 作为指导,但不起作用。
首先创建一个bootstrap/ConfigureLogging.php 类
<?php
namespace Bootstrap;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger as Monolog;
use Monolog\Formatter\LineFormatter;
use Illuminate\Log\Writer;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Bootstrap\ConfigureLogging as BaseConfigureLogging;
use Monolog\Handler\StreamHandler;
use Carbon\Carbon;
class ConfigureLogging extends BaseConfigureLogging
{
/**
* Configure the Monolog handlers for the application.
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \Illuminate\Log\Writer $log
* @return void
*/
protected function configureDailyHandler(Application $app, Writer $log)
{
$config = $app->make('config');
$maxFiles = $config->get('app.log_max_files');
// Formatting
// the default output format is "[%datetime%] %channel%.%level_name%: %message% %context% %extra%\n"
$logFormat = "[%datetime%] [%level_name%]: %message% %context% %extra%\n";
$formatter = new LineFormatter($logFormat);
//$logStreamHandler->setFormatter($formatter); // Here I'm lost
$log->useDailyFiles(
$app->storagePath().'/logs/cprsync.log', is_null($maxFiles) ? 5 : $maxFiles, $config->get('app.log_level', 'debug')
);
}
我的应用程序的 laravel 日志的此更改(覆盖)名称。 但是当我尝试为覆盖格式添加代码时,我迷路了,原始帖子上的代码不起作用。
我看到 Monolog 的代码,我看到我需要发送我的格式,但我不知道。
【问题讨论】:
标签: laravel-5.3 monolog