Skip to content

Instantly share code, notes, and snippets.

@vexus2
Created December 25, 2012 06:17
Show Gist options
  • Select an option

  • Save vexus2/4371866 to your computer and use it in GitHub Desktop.

Select an option

Save vexus2/4371866 to your computer and use it in GitHub Desktop.
PHP error_log拡張メソッド 呼び出しファイルやメソッド名を出力
/**
* 標準のerror_logメソッドを拡張し、呼び出し箇所の行数等を追加表示させる
*
* @param $message
* @param null $message_type
* @param null $destination
* @param null $extra_headers
*/
function e_log ($id, $message, $level = LEVEL_ERR , $message_type = null, $destination = null, $extra_headers = null ) {
error_log('---------------------------');
$backtraces = debug_backtrace();
$func_name = $backtraces[1]['function'];
$class_name = $backtraces[1]['class'];
$line = $backtraces[0]['line'];
error_log("[{$level}] $class_name#$func_name. line: $line");
//Cake標準や外部(Log4php)ログを使用すると複数サーバにログが散ってしまうため、エラーログで代用する
error_log( "[${id}] " . $message, $message_type, $destination, $extra_headers );
error_log('---------------------------');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment