mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-06 10:11:38 +09:00
Add option to control error and query log consolidation
This commit is contained in:
parent
3bf458e9ba
commit
58ce0defca
8 changed files with 90 additions and 41 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/**
|
||||
* Default configuration for Rhymix
|
||||
*
|
||||
*
|
||||
* Copyright (c) Rhymix Developers and Contributors
|
||||
*/
|
||||
return array(
|
||||
|
|
@ -103,6 +103,7 @@ return array(
|
|||
'display_to' => 'admin',
|
||||
'query_comment' => false,
|
||||
'query_full_stack' => false,
|
||||
'consolidate' => true,
|
||||
'write_error_log' => 'fatal',
|
||||
'allow' => array(),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -286,15 +286,23 @@ class Debug
|
|||
'type' => 'Debug',
|
||||
);
|
||||
|
||||
// Only add the same entry once.
|
||||
$key = hash_hmac('sha1', serialize([$entry->message, $entry->file, $entry->line]), config('crypto.authentication_key'));
|
||||
if (isset(self::$_entries[$key]))
|
||||
// Consolidate entries.
|
||||
if (!isset(self::$_config['consolidate']) || self::$_config['consolidate'] === true)
|
||||
{
|
||||
self::$_entries[$key]->count++;
|
||||
$key = hash_hmac('sha1', serialize([$entry->message, $entry->file, $entry->line]), config('crypto.authentication_key'));
|
||||
if (isset(self::$_entries[$key]))
|
||||
{
|
||||
self::$_entries[$key]->count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_entries[$key] = $entry;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_entries[$key] = $entry;
|
||||
$entry->count = 0;
|
||||
self::$_entries[] = $entry;
|
||||
}
|
||||
|
||||
// Add the entry to the error log.
|
||||
|
|
@ -354,14 +362,22 @@ class Debug
|
|||
);
|
||||
|
||||
// If the same error is repeated, only increment the counter.
|
||||
$key = hash_hmac('sha1', serialize([$errinfo->message, $errinfo->file, $errinfo->line]), config('crypto.authentication_key'));
|
||||
if (isset(self::$_errors[$key]))
|
||||
if (!isset(self::$_config['consolidate']) || self::$_config['consolidate'] === true)
|
||||
{
|
||||
self::$_errors[$key]->count++;
|
||||
$key = hash_hmac('sha1', serialize([$errinfo->message, $errinfo->file, $errinfo->line]), config('crypto.authentication_key'));
|
||||
if (isset(self::$_errors[$key]))
|
||||
{
|
||||
self::$_errors[$key]->count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_errors[$key] = $errinfo;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_errors[$key] = $errinfo;
|
||||
$errinfo->count = 0;
|
||||
self::$_errors[] = $errinfo;
|
||||
}
|
||||
|
||||
// Add the entry to the error log.
|
||||
|
|
@ -402,25 +418,34 @@ class Debug
|
|||
'type' => 'Query',
|
||||
);
|
||||
|
||||
// Generate a unique key for this query.
|
||||
$key = hash_hmac('sha1', serialize([
|
||||
$query_object->query_id,
|
||||
$query_object->query_string,
|
||||
$query_object->query_connection,
|
||||
$query_object->file,
|
||||
$query_object->line,
|
||||
$query_object->method,
|
||||
]), config('crypto.authentication_key'));
|
||||
|
||||
// If the same query is repeated, only increment the counter.
|
||||
if (isset(self::$_queries[$key]))
|
||||
// Consolidate repeated queries.
|
||||
if (!isset(self::$_config['consolidate']) || self::$_config['consolidate'] === true)
|
||||
{
|
||||
self::$_queries[$key]->query_time += $query_object->query_time;
|
||||
self::$_queries[$key]->count++;
|
||||
// Generate a unique key for this query.
|
||||
$key = hash_hmac('sha1', serialize([
|
||||
$query_object->query_id,
|
||||
$query_object->query_string,
|
||||
$query_object->query_connection,
|
||||
$query_object->file,
|
||||
$query_object->line,
|
||||
$query_object->method,
|
||||
]), config('crypto.authentication_key'));
|
||||
|
||||
// If the same query is repeated, only increment the counter.
|
||||
if (isset(self::$_queries[$key]))
|
||||
{
|
||||
self::$_queries[$key]->query_time += $query_object->query_time;
|
||||
self::$_queries[$key]->count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_queries[$key] = $query_object;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_queries[$key] = $query_object;
|
||||
$query_object->count = 0;
|
||||
self::$_queries[] = $query_object;
|
||||
}
|
||||
|
||||
// Record query time.
|
||||
|
|
@ -439,17 +464,26 @@ class Debug
|
|||
'type' => 'Query Error',
|
||||
);
|
||||
|
||||
// If the same query error is repeated, only increment the counter.
|
||||
$key = hash_hmac('sha1', serialize(['QUERY ERROR', $error_object->message, $error_object->file, $error_object->line]), config('crypto.authentication_key'));
|
||||
if (isset(self::$_errors[$key]))
|
||||
// Consolidate repeated queries.
|
||||
if (!isset(self::$_config['consolidate']) || self::$_config['consolidate'] === true)
|
||||
{
|
||||
self::$_errors[$key]->count++;
|
||||
$key = hash_hmac('sha1', serialize(['QUERY ERROR', $error_object->message, $error_object->file, $error_object->line]), config('crypto.authentication_key'));
|
||||
if (isset(self::$_errors[$key]))
|
||||
{
|
||||
self::$_errors[$key]->count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_errors[$key] = $error_object;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_errors[$key] = $error_object;
|
||||
$error_object->count = 0;
|
||||
self::$_errors[] = $error_object;
|
||||
}
|
||||
|
||||
// Add the entry to the error log.
|
||||
if (self::$_config['write_error_log'] === 'all')
|
||||
{
|
||||
$log_entry = strtr(sprintf('Query Error: %s in %s on line %d', $error_object->message, $error_object->file, intval($error_object->line)), "\0\r\n\t\v\e\f", ' ');
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ $(function() {
|
|||
if (data.entries[i].backtrace[j].file) {
|
||||
backtrace.append($('<li></li>').text(
|
||||
data.entries[i].backtrace[j].file + ":" + data.entries[i].backtrace[j].line +
|
||||
(j == 0 ? (" (×" + data.entries[i].count + ")") : "")
|
||||
((j == 0 && data.entries[i].count > 1) ? (" (×" + data.entries[i].count + ")") : "")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -119,7 +119,7 @@ $(function() {
|
|||
if (data.errors[i].backtrace[j].file) {
|
||||
backtrace.append($('<li></li>').text(
|
||||
data.errors[i].backtrace[j].file + ":" + data.errors[i].backtrace[j].line +
|
||||
(j == 0 ? (" (×" + data.errors[i].count + ")") : "")
|
||||
((j == 0 && data.errors[i].count > 1) ? (" (×" + data.errors[i].count + ")") : "")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ $(function() {
|
|||
if (data.queries[i].file && data.queries[i].line) {
|
||||
description.append($('<li></li>').text("Caller: " +
|
||||
data.queries[i].file + ":" + data.queries[i].line +
|
||||
(" (×" + data.queries[i].count + ")")
|
||||
(data.queries[i].count > 1 ? (" (×" + data.queries[i].count + ")") : "")
|
||||
).append("<br>(" + data.queries[i].method + ")"));
|
||||
description.append($('<li></li>').text("Connection: " + data.queries[i].query_connection));
|
||||
description.append($('<li></li>').text("Query ID: " + data.queries[i].query_id));
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ Debug Entries
|
|||
if (isset($backtrace['file']) && isset($backtrace['line']))
|
||||
{
|
||||
echo sprintf(' - %s line %d', $backtrace['file'], $backtrace['line']);
|
||||
if ($is_first_entry)
|
||||
if ($is_first_entry && $entry->count > 1)
|
||||
{
|
||||
echo ' (×' . $entry->count . ')';
|
||||
$is_first_entry = false;
|
||||
|
|
@ -87,7 +87,7 @@ PHP Errors and Warnings
|
|||
if (isset($backtrace['file']) && isset($backtrace['line']))
|
||||
{
|
||||
echo sprintf(' - %s line %d', $backtrace['file'], $backtrace['line']);
|
||||
if ($is_first_error)
|
||||
if ($is_first_error && $error->count > 1)
|
||||
{
|
||||
echo ' (×' . $error->count . ')';
|
||||
$is_first_error = false;
|
||||
|
|
@ -115,7 +115,7 @@ Database Queries
|
|||
echo sprintf('%02d. %s', ++$query_count, $query->query_string) . "\n";
|
||||
if (empty($query->backtrace))
|
||||
{
|
||||
echo sprintf(' - Caller: %s', $query_caller) . ' (×' . $query->count . ')' . "\n";
|
||||
echo sprintf(' - Caller: %s', $query_caller) . ($query->count > 1 ? (' (×' . $query->count . ')') : '') . "\n";
|
||||
}
|
||||
echo sprintf(' - Connection: %s', $query->query_connection) . "\n";
|
||||
echo sprintf(' - Query ID: %s', $query->query_id) . "\n";
|
||||
|
|
@ -123,7 +123,7 @@ Database Queries
|
|||
echo sprintf(' - Result: %s', $query_result) . "\n";
|
||||
if (!empty($query->backtrace))
|
||||
{
|
||||
echo sprintf(' - Call Stack: %s', $query_caller) . ' (×' . $query->count . ')' . "\n";
|
||||
echo sprintf(' - Call Stack: %s', $query_caller) . ($query->count > 1 ? (' (×' . $query->count . ')') : '') . "\n";
|
||||
foreach ($query->backtrace ?? [] as $key => $backtrace)
|
||||
{
|
||||
if (isset($backtrace['file']) && isset($backtrace['line']))
|
||||
|
|
|
|||
|
|
@ -25,10 +25,11 @@ class Debug extends Base
|
|||
Context::set('debug_log_filename', Config::get('debug.log_filename') ?: 'files/debug/YYYYMMDD.php');
|
||||
Context::set('debug_display_type', (array)Config::get('debug.display_type'));
|
||||
Context::set('debug_display_content', Config::get('debug.display_content'));
|
||||
Context::set('debug_display_to', Config::get('debug.display_to'));
|
||||
Context::set('debug_query_comment', Config::get('debug.query_comment'));
|
||||
Context::set('debug_query_full_stack', Config::get('debug.query_full_stack'));
|
||||
Context::set('debug_write_error_log', Config::get('debug.write_error_log'));
|
||||
Context::set('debug_display_to', Config::get('debug.display_to') ?? 'admin');
|
||||
Context::set('debug_query_comment', Config::get('debug.query_comment') ?? false);
|
||||
Context::set('debug_query_full_stack', Config::get('debug.query_full_stack') ?? false);
|
||||
Context::set('debug_consolidate', Config::get('debug.consolidate') ?? true);
|
||||
Context::set('debug_write_error_log', Config::get('debug.write_error_log') ?? 'fatal');
|
||||
|
||||
// IP access control
|
||||
$allowed_ip = Config::get('debug.allow');
|
||||
|
|
@ -60,6 +61,7 @@ class Debug extends Base
|
|||
Config::set('debug.display_to', strval($vars->debug_display_to) ?: 'admin');
|
||||
Config::set('debug.query_comment', $vars->debug_query_comment === 'Y');
|
||||
Config::set('debug.query_full_stack', $vars->debug_query_full_stack === 'Y');
|
||||
Config::set('debug.consolidate', $vars->debug_consolidate === 'Y');
|
||||
Config::set('debug.write_error_log', strval($vars->debug_write_error_log) ?: 'fatal');
|
||||
|
||||
// Debug content
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ $lang->debug_display_to_everyone = 'Everyone';
|
|||
$lang->debug_log_filename = 'Log filename';
|
||||
$lang->debug_query_comment = 'Add Comment to Queries';
|
||||
$lang->debug_query_full_stack = 'Show Complete Call Stack for Queries';
|
||||
$lang->debug_consolidate = 'Consolidate Entries';
|
||||
$lang->debug_write_error_log = 'Write to Error Log';
|
||||
$lang->debug_write_error_log_all = 'All errors and warnings';
|
||||
$lang->debug_write_error_log_fatal = 'Fatal errors only';
|
||||
|
|
@ -243,6 +244,7 @@ $lang->about_debug_error_log_path = 'The error log location that is currently co
|
|||
$lang->about_debug_error_log_path_empty = '(none)';
|
||||
$lang->about_debug_query_comment = 'Add a comment containing the query name and IP address to every SQL statement. This may help you determine where slow queries are coming from.';
|
||||
$lang->about_debug_query_full_stack = 'Show the complete call stack for each query. This can increase the size of debug data considerably.';
|
||||
$lang->about_debug_consolidate = 'Show only one entry for errors and queries that occur in the same location, along with the number of times they occurred.';
|
||||
$lang->msg_debug_log_filename_not_writable = 'Rhymix cannot write log files in the specified path.';
|
||||
$lang->debug_allowed_ip = 'Allowed IP addresses';
|
||||
$lang->seo_main_title = 'Main Page Title';
|
||||
|
|
|
|||
|
|
@ -229,6 +229,7 @@ $lang->debug_display_to_everyone = '모두에게 표시';
|
|||
$lang->debug_log_filename = '디버그 정보 기록 파일';
|
||||
$lang->debug_query_comment = '쿼리에 주석 추가';
|
||||
$lang->debug_query_full_stack = '쿼리 콜 스택 전체 표시';
|
||||
$lang->debug_consolidate = '중복 항목 정리';
|
||||
$lang->debug_write_error_log = '에러 로그에 기록';
|
||||
$lang->debug_write_error_log_all = '모든 에러와 경고를 기록';
|
||||
$lang->debug_write_error_log_fatal = '치명적인 에러만 기록';
|
||||
|
|
@ -239,6 +240,7 @@ $lang->about_debug_error_log_path = '현재 php.ini에서 설정된 에러 로
|
|||
$lang->about_debug_error_log_path_empty = '(없음)';
|
||||
$lang->about_debug_query_comment = '쿼리명과 IP 주소를 포함하는 주석을 모든 쿼리에 추가하여, 부하를 유발하는 쿼리 및 방문자를 DB에서 쉽게 파악할 수 있도록 합니다.';
|
||||
$lang->about_debug_query_full_stack = '쿼리와 관련된 콜 스택을 모두 표시합니다. 디버그 정보의 분량이 크게 늘어날 수 있습니다.';
|
||||
$lang->about_debug_consolidate = '동일한 위치에서 반복하여 발생하는 오류나 쿼리는 한 번만 기록하고, 발생 횟수를 표시합니다.';
|
||||
$lang->msg_debug_log_filename_not_writable = '지정한 경로에 로그 파일을 작성할 수 없습니다.';
|
||||
$lang->debug_allowed_ip = '디버그 허용 IP';
|
||||
$lang->seo_main_title = '메인화면 제목';
|
||||
|
|
|
|||
|
|
@ -103,6 +103,14 @@
|
|||
<p class="x_help-block">{$lang->about_debug_query_full_stack}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->debug_consolidate}</label>
|
||||
<div class="x_controls">
|
||||
<label for="debug_consolidate_Y" class="x_inline"><input type="radio" name="debug_consolidate" id="debug_consolidate_Y" value="Y" checked="checked"|cond="$debug_consolidate" /> {$lang->cmd_yes}</label>
|
||||
<label for="debug_consolidate_N" class="x_inline"><input type="radio" name="debug_consolidate" id="debug_consolidate_N" value="N" checked="checked"|cond="!$debug_consolidate" /> {$lang->cmd_no}</label>
|
||||
<p class="x_help-block">{$lang->about_debug_consolidate}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->debug_write_error_log}</label>
|
||||
<div class="x_controls">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue