質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

解決済

2回答

6087閲覧

【cakephp3】DB登録失敗時のエラーログ出力の方法

ponpoko6012

総合スコア18

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

0グッド

0クリップ

投稿2016/04/15 12:22

cakephp3にてDBへのsave処理がエラーだった場合、原因を探る為のエラーログを出力するにはどうすればよいでしょうか?

save処理で失敗してflashのエラーメッセージが表示されても、logsフォルダ配下のdebug.log、error.logには何も出力されません。
よい方法をご存じの方、ご教授願います。

cakephpバージョン:3.2.7

if ($this->Hoge->save($hoge)) { $this->Flash->success(__('The link item has been saved.')); return $this->redirect(['action' => 'index']); } else { $this->Flash->error(__('The link item could not be saved. Please, try again.')); }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

デバッグツールのSQLログで確認するようにしました。

投稿2016/05/02 04:21

編集2016/05/02 04:26
ponpoko6012

総合スコア18

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

今手元に試せる環境がありませんので、上手く行かなかったらごめんなさい。

デバッグモードのレベルはいくつに設定されていますか?

app/Config/core.php の35行目付近に

Configure::write('debug', X);

という箇所があるので、X = 2 にすると良いみたいですよ。

下記を参考に頑張ってください。
デバッグの仕方

投稿2016/04/16 02:48

pi-chan

総合スコア5936

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ponpoko6012

2016/04/18 05:28

回答ありがとうございます。 ただ、cakephp3ではcore.phpは廃止されたようです。 設定関連はconfig/app.phpで行うようなのですが、下記設定にしていてもsave処理失敗時にエラーログは出力されませんでした。 /** * Debug Level: * * Production Mode: * false: No error messages, errors, or warnings shown. * * Development Mode: * true: Errors and warnings shown. */ 'debug' => true, (中略) /** * Configure the Error and Exception handlers used by your application. * * By default errors are displayed using Debugger, when debug is true and logged * by Cake\Log\Log when debug is false. * * In CLI environments exceptions will be printed to stderr with a backtrace. * In web environments an HTML page will be displayed for the exception. * With debug true, framework errors like Missing Controller will be displayed. * When debug is false, framework errors will be coerced into generic HTTP errors. * * Options: * * - `errorLevel` - int - The level of errors you are interested in capturing. * - `trace` - boolean - Whether or not backtraces should be included in * logged errors/exceptions. * - `log` - boolean - Whether or not you want exceptions logged. * - `exceptionRenderer` - string - The class responsible for rendering * uncaught exceptions. If you choose a custom class you should place * the file for that class in src/Error. This class needs to implement a * render method. * - `skipLog` - array - List of exceptions to skip for logging. Exceptions that * extend one of the listed exceptions will also be skipped for logging. * E.g.: * `'skipLog' => ['Cake\Network\Exception\NotFoundException', 'Cake\Network\Exception\UnauthorizedException']` * - `extraFatalErrorMemory` - int - The number of megabytes to increase * the memory limit by when a fatal error is encountered. This allows * breathing room to complete logging or error handling. */ 'Error' => [ 'errorLevel' => E_ALL & ~E_DEPRECATED, 'exceptionRenderer' => 'Cake\Error\ExceptionRenderer', 'skipLog' => [], 'log' => true, 'trace' => true, ], (中略) /** * Configures logging options */ 'Log' => [ 'debug' => [ 'className' => 'Cake\Log\Engine\FileLog', 'path' => LOGS, 'file' => 'debug', 'levels' => ['notice', 'info', 'debug'], ], 'error' => [ 'className' => 'Cake\Log\Engine\FileLog', 'path' => LOGS, 'file' => 'error', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], ], ], DBへのsave処理失敗時はどのように調査するのでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問