このページの2つのバージョン間の差分を表示します。
| 次のリビジョン | 前のリビジョン | ||
|
apricot:usage:ja:errors-logging [2020/07/29 13:33] tanaka 作成 |
apricot:usage:ja:errors-logging [2020/09/10 18:02] (現在) y2sunlight [アセットファイル] |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | > 編集中 | ||
| - | |||
| - | ---- | ||
| - | |||
| ====== Apricot ログとエラー処理 ====== | ====== Apricot ログとエラー処理 ====== | ||
| --- // | --- // | ||
| - | [[apricot: | + | [[apricot: |
| 目次 | 目次 | ||
| + | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| + | * Apricot ログとエラー処理 | ||
| * [[apricot: | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| - | * [[apricot: | + | * [[apricot: |
| + | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| - | * Apricot ログとエラー処理 | + | * [[apricot: |
| + | * [[apricot: | ||
| + | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| 行 22: | 行 23: | ||
| ===== ロギング ===== | ===== ロギング ===== | ||
| - | >TODO | + | |
| + | ロギングは、[[https:// | ||
| + | |||
| + | 使用法: **Log:: | ||
| + | |||
| + | ^メソッド^機能^ | ||
| + | |emergency(string $message, array $context = [])|emergencyレベルのログ| | ||
| + | |alert(string $message, array $context = [])|alertレベルのログ| | ||
| + | |critical(string $message, array $context = [])|criticalレベルのログ| | ||
| + | |error(string $message, array $context = [])|errorレベルのログ| | ||
| + | |warning(string $message, array $context = [])|warningレベルのログ| | ||
| + | |notice(string $message, array $context = [])|noticeレベルのログ| | ||
| + | |info(string $message, array $context = [])|infoレベルのログ| | ||
| + | |debug(string $message, array $context = [])|debugレベルのログ| | ||
| + | |log($level, | ||
| + | |||
| + | 使用例: | ||
| + | |||
| + | <code php> | ||
| + | use Apricot\Log; | ||
| + | Log:: | ||
| + | </code> | ||
| \\ | \\ | ||
| - | ===== エラーハンドラーの設定 ===== | + | ==== 設定ファイル |
| - | >TODO | + | |
| + | ロギングには以下の設定ファイルが存在します。 | ||
| + | |||
| + | {{fa> | ||
| + | <code php monolog.setting.php> | ||
| + | <?php | ||
| + | /** | ||
| + | * This file contains Monolog settings. | ||
| + | */ | ||
| + | return | ||
| + | [ | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ]; | ||
| + | </ | ||
| + | |||
| + | * name --- ログの名前 (初期設定は、環境変数APP_NAME(無ければAPP_NAME)の値) | ||
| + | * path --- ログの出力パス (初期設定は、var/ | ||
| + | * level --- ログの出力レベル (初期設定は、' | ||
| + | * max_files --- ログファイルの最大保存数 (初期設定は、0(無制限)) | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ===== デバッグ出力 ===== | ||
| + | |||
| + | Apricotではオンサイトでのデバッグ出力機能を実現するために、[[https:// | ||
| + | |||
| + | ==== DebugBarクラス ==== | ||
| + | |||
| + | '' | ||
| + | |||
| + | 使用法: **DebugBar:: | ||
| + | |||
| + | ^メソッド^機能^ | ||
| + | |renderHead(): | ||
| + | |render(): | ||
| + | |getCollector(string $name=" | ||
| + | |||
| + | こららのメソッドの内、'' | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ==== Debugクラス ==== | ||
| + | '' | ||
| + | |||
| + | 使用法: ** Debug:: | ||
| + | |||
| + | ^メソッド^機能^ | ||
| + | |emergency($message, | ||
| + | |alert($message, | ||
| + | |critical($message, | ||
| + | |error($message, | ||
| + | |warning($message, | ||
| + | |notice($message, | ||
| + | |info($message, | ||
| + | |debug($message, | ||
| + | |log($level, | ||
| + | |||
| + | 使用例: | ||
| + | |||
| + | <code php> | ||
| + | use Apricot\Debug; | ||
| + | Debug:: | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ==== 設定ファイル ==== | ||
| + | |||
| + | デバッグ出力には以下の設定ファイルが存在します。 | ||
| + | |||
| + | {{fa> | ||
| + | <code php debugbar.setting.php> | ||
| + | <?php | ||
| + | /** | ||
| + | * This file contains DebugBer settings. | ||
| + | */ | ||
| + | return | ||
| + | [ | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ], | ||
| + | ]; | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | '' | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ==== アセットファイル ==== | ||
| + | |||
| + | 設定値の '' | ||
| + | |||
| + | < | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | < | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | デバッグ出力で使用するアセットファイルは、以下のディレクトリーに保存されているので、この下の全てのファイルとディレクリーを上記の場所にコピーして下さい。 | ||
| + | |||
| + | < | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | 結果的に手動の場合のアセットファイルの配置は以下のようになります: | ||
| + | |||
| + | {{fa> | ||
| + | < | ||
| + | vendor/ | ||
| + | widgets/ | ||
| + | debugbar.css | ||
| + | debugbar.js | ||
| + | openhandler.css | ||
| + | openhandler.js | ||
| + | widgets.css | ||
| + | widgets.js | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ===== 集約例外ハンドラー ===== | ||
| + | |||
| + | Apricotでは例外ハンドラーとして[[https:// | ||
| + | |||
| + | 集約例外ハンドラーの動作にはデバッグモードと本番モードがあります。 | ||
| + | |||
| + | * デバッグモード --- ログ出力して、例外内容とスタックトレースを表示する | ||
| + | * 本番モード --- ログ出力して、利用者向けのエラーページを表示する | ||
| + | |||
| + | これらの動作をカスタマイズするには、以下のWhoopsのセットアップファイルを変更して下さい。 | ||
| + | |||
| + | セットアップファイル: | ||
| + | < | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ==== 設定ファイル ==== | ||
| + | |||
| + | 例外ハンドラーには以下の設定ファイルが存在します。 | ||
| + | |||
| + | {{fa> | ||
| + | <code php whoops.setting.php> | ||
| + | <?php | ||
| + | /** | ||
| + | * This file contains Whoops settings. | ||
| + | */ | ||
| + | return | ||
| + | [ | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ]; | ||
| + | </ | ||
| + | |||
| + | * debug --- デバッグモードの場合 true (初期設定は、環境変数APP_DEBUGの値。無ければfalse) | ||
| + | * controller --- 集約例外コントローラクラスを指定する (次項参照) | ||
| + | * action --- 集約例外コントローラのアクションメソッド名を指定する (次項参照) | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ==== 集約例外コントローラ | ||
| + | |||
| + | 本番モードで集約例外ハンドラーから呼び出されるコントローラを集約例外コントローラと呼びます。上述の whoops.setting.php での設定に従い、例外発生時に '' | ||
| + | |||
| + | 初期実装されている集約例外コントローラでは、例外の種類に応じてHTTPステータスコードを以下のように設定します。 | ||
| + | |||
| + | * CSRFエラーなどの TokenMismatchException( トークンエラー )は419( Page Expired )に設定 | ||
| + | * HttpException( ボイラープレート '' | ||
| + | * その他の例外は 500( Internal Server Error )に設定 | ||
| + | |||
| + | 集約例外コントローラは以下に配置されています。必要に応じてカスタマイズできます。 | ||
| + | |||
| + | <code> | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ===== コアの例外クラス ===== | ||
| + | |||
| + | Exceptionを継承した2つの例外クラスがあります。 | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | ==== abort() ==== | ||
| + | |||
| + | '' | ||
| + | |||
| + | <code php> | ||
| + | abort(400); | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | <code php> | ||
| + | /** | ||
| + | * Throws an HTTP exception. | ||
| + | * | ||
| + | * @param int $code | ||
| + | * @param string $message | ||
| + | * @throws \Apricot\Exceptions\HttpException | ||
| + | */ | ||
| + | function abort(int $code, string $message=null) | ||
| + | { | ||
| + | throw new Apricot\Exceptions\HttpException($code, | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ===== アプリの例外クラス ===== | ||
| + | |||
| + | '' | ||
| + | |||
| + | * '' | ||
| + | |||
| + | \\ | ||
| + | |||
| + | ===== エラーバッグ ===== | ||
| + | |||
| + | エラーバッグ( '' | ||
| + | |||
| + | ErrorBag には名前を付けることができます( self:: | ||
| + | |||
| + | ^メソッド^機能^ | ||
| + | |< | ||
| + | |count(string $name=null): | ||
| + | |has(string $key, string $name=self:: | ||
| + | |get(string $key, string $name=self:: | ||
| + | |all(string $name=null): | ||
| + | |put($errors)|エラー配列の設定| | ||
| + | |||
| + | エラーバッグは[[https:// | ||
| + | |||
| + | バリデーションエラー用の [[apricot: | ||
| \\ | \\ | ||