0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【phpbb】エラーをロギング

Posted at

はじめに

phpbb3.2を使っています。
/var/log/httpd/error_logにエラーが出てこず、phpbbでエラーログ出している人いるかなと思いググっても、困っている人はそれなりにいるにも関わらずACPで見ることのできるログの情報しか出てこなくて、結局以下の方法で対応しました。

コード

config.php
@define('PHPBB_ENVIRONMENT', 'production');

config.phpで'development'以外が対象です。

common.php
if (PHPBB_ENVIRONMENT === 'development')
{
	\phpbb\debug\debug::enable();
}
else
{
	set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler');
}

PHPBB_ENVIRONMENT === 'development'でないときはset_error_handler()defined('PHPBB_MSG_HANDLER')がなければmsg_handlerがセットされます。

msg_handlerincludes/functions.phpにあります。

includes/functions.php
* Error and message handler, call with trigger_error if read
*/
function msg_handler($errno, $msg_text, $errfile, $errline)
{

### 略###

    // phpbb does not have logging system so added error_log
    if ($errno == E_ERROR || $errno == E_USER_ERROR) {
        error_log(
            implode(" ", array(
                "errorno:".$errno,
                "msg_text:[".$msg_text."]",
                "errfile:[".$errfile."]",
                "errline:".$errline,
                "phpbb_root_path:[".$phpbb_root_path."]",
                "msg_title:[".$msg_title."]",
                "msg_long_text:[".$msg_long_text."]"
            ))
        )
    }

	switch ($errno)
	{
		case E_NOTICE:
		case E_WARNING:


function msg_handlerswitch ($errno)しているところがあります。
今回はそのあたりにerror_logでロギングするようにしました。
ログの書き方は適宜変えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?