2016-12-30 10 views
1

私は、ガイドこのpostとして使用しますが、動作しませんLaravel 5.3オーバーライド形式のログ

で作られたプロジェクトで形式のログを無効にする必要があります。

まず、ブートストラップ/ ConfigureLogging.phpクラス私のアプリのためのlaravelログの

<?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') 
     ); 
} 

この変更(オーバーライド)の名前を作成します。 しかし、オーバーライド形式のコードを追加しようとすると、私は失われてしまい、元の投稿のコードは機能しません。

私はMonologのコードを参照しています。フォーマットを送信する必要があることがわかりますが、わかりません。

答えて

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); 
} 
+0

ありがとうございました。あなたは、プッシュハンドラのメカニズムをよく理解しています。そしてうまくいく。 – abkrim

+1

まあ、ログの特別な情報ではないときに、行末の余分な括弧を削除するには '$ formatter = new LineFormatter($ logFormat、null、true、true); 'を使用します。 – abkrim

関連する問題