Readouble

Laravel 5.dev エラーとログ

設定Configuration

アプリケーションのログ機能はIlluminate\Foundation\Bootstrap\ConfigureLogging初期化クラスの中で設定されています。このクラスはconfig/app.php設定ファイルのlogオプションを参照しています。The logging facilities for your application are configured in the Illuminate\Foundation\Bootstrap\ConfigureLogging bootstrapper class. This class utilizees the log configuration option from your config/app.php configuration file.

デフォルトでログ機能は日毎のログファイルを使用するように設定されています。しかし、必要に応じてカスタマイズできます。Laravelでは、人気のあるMonologログライブラリーを使用しており、Monologが提供する様々なハンドラーを利用することができます。By default, the logger is configured to use daily log files; however, you may customize this behavior as needed. Since Laravel uses the popular Monolog[https://github.com/Seldaek/monolog] logging library, you can take advantage of the variety of handlers that Monolog offers.

例えば、日別のファイルの代わりに同じログファイルを使いたいのでしたら、config/app.php設定ファイルを以下のように変更してください。For example, if you wish to use a single log file instead of daily files, you can make the following change to your config/app.php configuration file:

'log' => 'single'

初めからLaravelは、単一ファイル(single)、日別ファイル(daily)、 システムログ(syslog)をサポートしています。しかし、アプリケーションのためにログをカスタマイズしたいのでしたら、ConfigureLogging初期設定クラスを自由にオーバーライドできます。Out of the box, Laravel supported single, daily, and syslog logging modes. However, you are free to customize the logging for your application as you wish by overriding the ConfigureLogging bootstrapper class.

エラー詳細Error Detail

config/app.php設定ファイルのapp.debug設定オプションにより、ブラウザに出力されるアプリケーションのエラー詳細をコントロールできます。デフォルトでは、この設定オプションは、.envファイルで設定されているAPP_DEBUG環境変数を反映するように設定されています。The amount of error detail your application displays through the browser is controlled by the app.debug configuration option in your config/app.php configuration file. By default, this configuration option is set to respect the APP_DEBUG environment variable, which is stored in your .env file.

ローカル環境では、APP_DEBUG環境変数をtureに設定すべきでしょう。実働環境では、この値は常にfalseにしておいてください。For local development, you should set the APP_DEBUG environment variable to true. In your production environment, this value should always be false.

エラーの処理Handling Errors

全例外はApp\Exceptions\Handlerクラスで処理されます。このクラスはreportrenderメソッドで構成されています。All exceptions are handled by the App\Exceptions\Handler class. This class contains two methods: report and render.

reportメソッドは例外のログや、BugSnagのような外部サービスにメールで送るために使用します。デフォルトでは、例外をログしている親のクラスの基本的な実装へ渡すだけです。しかし、例外をお好きなようにログしてかまいません。それぞれのタイプ例外を異なった方法でログする必要があれば、PHPのinstanceof比較演算子が使えます。The report method is used to log exceptions or send them to an external service like BugSnag[https://bugsnag.com]. By default, the report method simply passes the exception to the base implementation on the parent class where the exception is logged. However, you are free to log exceptions however you wish. If you need to report different types of exceptions in different ways, you may use the PHP instanceof comparison operator:

/**
 * 例外をレポートもしくはログする
 *
 * SentryやBugsnagなどにレポートするために最適な場所
 *
 * @param  \Exception  $e
 * @return void
 */
public function report(Exception $e)
{
	if ($e instanceof CustomException)
	{
		//
	}

	return parent::report($e);
}

renderメソッドは例外をHTTPレスポンスに変換し、ブラウザに送り返す役割を持っています。デフォルトでは、例外はレスポンスを生成するベースクラスへ渡されます。しかし、例外のタイプを調べ、カスタムレスポンスを返すのも自由です。The render method is responsible for converting the exception into an HTTP response that should be sent back to the browser. By default, the exception is passed to the base class which generates a response for you. However, you are free to check the exception type or return your own custom response.

例外ハンドラーのdontReportプロパティは、ログしない例外タイプの配列で構成されています。デフォルトでは、404エラーを示す例外はログファイルに書き込まれません。必要に応じ、他の例外タイプを配列に追加してください。The dontReport property of the exception handler contains an array of exception types that will not be logged. By default, exceptions resulting from 404 errors are not written to your log files. You may add other exception types to this array as needed.

HTTP例外HTTP Exceptions

いくつかの例外は、サーバーからのHTTPエラーコードを表しています。例えば、「ページが見つかりません(404)」であったり、「認証されていないエラー(401)」であったり、開発者が発生させた500エラーであることもあるでしょう。このようなレスポンスをリターンしたい場合には、以下のように行なってください。Some exceptions describe HTTP error codes from the server. For example, this may be a "page not found" error (404), an "unauthorized error" (401) or even a developer generated 500 error. In order to return such a response, use the following:

abort(404);

オプションとして、理由を説明することもできます。Optionally, you may provide a response:

abort(403, 'Unauthorized action.');

このメソッドはリクエストのライフサイクル中であれば、いつでも使用できます。This method may be used at any time during the request's lifecycle.

404エラーページのカスタマイズCustom 404 Error Page

全ての404エラーでカスタムビューを返すためには、resources/views/errors/404.blade.phpファイルを作成してください。アプリケーションで起きる全404エラーに対し、このビューが表示されるようになります。To return a custom view for all 404 errors, create a resources/views/errors/404.blade.php file. This view will be served on all 404 errors generated by your application.

ログLogging

Laravelのログ機能は、強力なMonologライブラリーのシンプルな上位レイヤーを提供しています。Laravelはデフォルトで、アプリケーションの日別ログファイルをstorage/logsディレクトリーへ作成するように設定されています。ログへ情報を書き込みたい場合は、以下のように行います。The Laravel logging facilities provide a simple layer on top of the powerful Monolog[http://github.com/seldaek/monolog] library. By default, Laravel is configured to create daily log files for your application which are stored in the storage/logs directory. You may write information to the log like so:

Log::info('これは便利な情報です。');

Log::warning('なんだか悪いことが起きているかも知れません。');

Log::error('何か本当に悪いことが起きています。');

ログはRFC 5424で定義されているdebuginfonoticewarningerrorcriticalalertの7レベルをサポートしています。The logger provides the seven logging levels defined in RFC 5424[http://tools.ietf.org/html/rfc5424]: debug, info, notice, warning, error, critical, and alert.

ログメソッドにはコンテキストデーターを配列で渡すこともできます。An array of contextual data may also be passed to the log methods:

Log::info('Log message', ['context' => 'Other helpful information']);

Monologにはログに使えるその他の多彩なハンドラーが用意されています。必要であれば、Laravelが内部で使用しているMonologインスタンスへアクセスすることもできます。Monolog has a variety of additional handlers you may use for logging. If needed, you may access the underlying Monolog instance being used by Laravel:

$monolog = Log::getMonolog();

ログに渡される全てのメッセージを捉えるため、イベントを登録することもできます。You may also register an event to catch all messages passed to the log:

ログイベントリスナーの登録Registering A Log Event Listener

Log::listen(function($level, $message, $context)
{
	//
});

章選択

Artisan CLI

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作