Laravel 5에서 로깅 설정 변경하기

Submitted by river - 등록 8 years ago - 수정 8 years ago

Illuminate\Foundation\Bootstrap\ConfigureLogging 오버라이딩

bootstrap\ConfigureLogging.php 생성

<?php namespace Bootstrap;

use Illuminate\Log\Writer;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Bootstrap\ConfigureLogging as BaseConfigureLogging;
use Monolog\Processor\MemoryUsageProcessor;
use Monolog\Processor\WebProcessor;

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 configureHandlers(Application $app, Writer $log)
    {
        parent::configureHandlers($app, $log);

        $logger = $log->getMonolog();

        // processor, adding URI, IP address etc. to the log
        $logger->pushProcessor(new WebProcessor);

        // processor, memory usage
        $logger->pushProcessor(new MemoryUsageProcessor);
    }
}

composer.json 수정

"autoload": {
...
    "psr-4": {
        "App\\": "app/",
        "Bootstrap\\": "bootstrap/"
     },
...
},

/app/Http/Kernel.php 수정

<?php
...
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Routing\Router;
...

...
public function __construct(Application $app, Router $router)
{
    parent::__construct($app, $router);

    array_walk($this->bootstrappers, function (&$bootstrapper) {
        if ($bootstrapper === 'Illuminate\Foundation\Bootstrap\ConfigureLogging') {
            $bootstrapper = 'Bootstrap\ConfigureLogging';
        }
    });
}

관련글

comments powered by Disqus