我需要覆盖使用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的代码,我看到我需要发送我的格式,但我不知道。
答案 0 :(得分:1)
您所指的链接应该符合我的知识。您遗失了pushHandler
protected function configureDailyHandler(Application $app, Writer $log) {
$config = $app->make('config');
$maxFiles = $config->get('app.log_max_files');
$path = $app->storagePath().'/logs/cprsync.log';
// Daily handler
$handler = new RotatingFileHandler($path, is_null($maxFiles) ? 5 : $maxFiles,
$config->get('app.log_level', 'debug'));
// Formatting
$logFormat = "%datetime% [%level_name%] (%channel%): %message% %context% %extra%\n";
$formatter = new LineFormatter($logFormat);
$handler->setFormatter($formatter);
// Push handler
$log->getMonolog()->pushHandler($handler);
}