2016-05-20 3 views
3

Documentantionは言う:デフォルトでルーメン(5.1.6)日次ログ

、ルーメンは、ストレージ/ logsディレクトリに格納されているアプリケーションの毎日のログファイルを作成するように構成されています。

私のアプリケーションでは、毎日のログなしでlumen.logが生成されます。

私のバージョン:Laravel FrameworkバージョンLumen(5.1.6)(Laravel Components 5.1。*)5.1インストールから来ました。

日次ファイルでログを生成するにはどうすればよいですか?

答えて

8

this commit以降、configureMonologUsingメソッドがあります。あなたのブートストラップ/ app.phpファイル

use Monolog\Formatter\LineFormatter; 
use Monolog\Handler\RotatingFileHandler; 

$app->configureMonologUsing(function ($monolog) { 
    $maxFiles = 7; 

    $rotatingLogHandler = (new RotatingFileHandler(storage_path('logs/lumen.log'), $maxFiles)) 
     ->setFormatter(new LineFormatter(null, null, true, true)); 

    $monolog->setHandlers([$rotatingLogHandler]); 

    return $monolog; 
}); 

あなたは新しい回転ログハンドラを作成し、モノローグハンドラを置き換えるサービスプロバイダを作成することができますに、このメソッドの呼び出しを配置する必要があります。

<?php 

namespace App\Providers; 

use Illuminate\Support\ServiceProvider; 
use Monolog\Formatter\LineFormatter; 
use Monolog\Handler\RotatingFileHandler; 

class LogServiceProvider extends ServiceProvider 
{ 
    public function boot() 
    { 
     app('Psr\Log\LoggerInterface')->setHandlers([$this->getRotatingLogHandler()]); 
    } 

    public function getRotatingLogHandler($maxFiles = 7) 
    { 
     return (new RotatingFileHandler(storage_path('logs/lumen.log'), $maxFiles)) 
      ->setFormatter(new LineFormatter(null, null, true, true)); 
    } 

    public function register() 
    { 
    } 
} 

また、アプリケーションを拡張し、getMonologHandlerまたはregisterLogBindingsメソッドを置き換えることができます。以下は前者を置き換える例です。

ブートストラップに/ start.php

// This 
$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../') 
); 

// With this 
$app = new App\Application(
    realpath(__DIR__.'/../') 
); 

を交換して、アプリケーション\ Application.phpを作成

<?php 

namespace App; 

use Monolog\Formatter\LineFormatter; 
use Monolog\Handler\RotatingFileHandler; 
use Laravel\Lumen\Application as LumenApplication; 

class Application extends LumenApplication 
{ 
    /** 
    * {@inheritdoc} 
    */ 
    protected function getMonologHandler() 
    { 
     $maxRotatedFiles = 3 

     return (new RotatingFileHandler(storage_path('logs/lumen.log'), $maxRotatedFiles)) 
      ->setFormatter(new LineFormatter(null, null, true, true)); 
    } 
} 
+0

ベン・スウィンバーン@グレート答え!新しいサービスプロバイダを作成するとうまくいきます! – Sangar82