Index: branches/5.2.x/core/install/install_data.sql
===================================================================
diff -u -r16686 -r16754
--- branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 16686)
+++ branches/5.2.x/core/install/install_data.sql (.../install_data.sql) (revision 16754)
@@ -104,6 +104,7 @@
INSERT INTO SystemSettings VALUES(DEFAULT, 'EmailLogRotationInterval', '2419200', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_EmailLogRotationInterval', 'select', NULL, '86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2419200=la_opt_OneMonth||7257600=la_opt_ThreeMonths||29030400=la_opt_OneYear||-1=la_opt_EmailLogKeepForever', 65.02, 0, 0, 'hint:la_config_EmailLogRotationInterval');
INSERT INTO SystemSettings VALUES(DEFAULT, 'SystemLogRotationInterval', '2419200', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SystemLogRotationInterval', 'select', NULL, '86400=la_opt_OneDay||604800=la_opt_OneWeek||1209600=la_opt_TwoWeeks||2419200=la_opt_OneMonth||7257600=la_opt_ThreeMonths||29030400=la_opt_OneYear||-1=la_opt_SystemLogKeepForever', 65.03, 0, 1, 'hint:la_config_SystemLogRotationInterval');
INSERT INTO SystemSettings VALUES(DEFAULT, 'SystemLogNotificationEmail', '', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SystemLogNotificationEmail', 'text', 'a:5:{s:4:"type";s:6:"string";s:9:"formatter";s:10:"kFormatter";s:6:"regexp";s:85:"/^([-a-zA-Z0-9!\\#$%&*+\\/=?^_`{|}~.]+@[a-zA-Z0-9]{1}[-.a-zA-Z0-9_]*\\.[a-zA-Z]{2,6})$/i";s:10:"error_msgs";a:1:{s:14:"invalid_format";s:18:"!la_invalid_email!";}s:7:"default";s:0:"";}', NULL, 65.04, 0, 1, 'hint:la_config_SystemLogNotificationEmail');
+INSERT INTO SystemSettings VALUES(DEFAULT, 'SystemLogCodeFragmentPathFilterRegExp', '#(modules/custom|system/cache/modules/custom)/.*#', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SystemLogCodeFragmentPathFilterRegExp', 'text', NULL, NULL, 65.05, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'CSVExportDelimiter', '1', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsCSVExport', 'la_config_CSVExportDelimiter', 'select', NULL, '0=la_opt_Tab||1=la_opt_Comma||2=la_opt_Semicolon||3=la_opt_Space||4=la_opt_Colon', 70.01, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'CSVExportEnclosure', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsCSVExport', 'la_config_CSVExportEnclosure', 'radio', NULL, '0=la_Doublequotes||1=la_Quotes', 70.02, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'CSVExportSeparator', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsCSVExport', 'la_config_CSVExportSeparator', 'radio', NULL, '0=la_Linux||1=la_Windows', 70.03, 0, 1, NULL);
Index: branches/5.2.x/core/admin_templates/logs/system_logs/system_log_edit.tpl
===================================================================
diff -u -r16715 -r16754
--- branches/5.2.x/core/admin_templates/logs/system_logs/system_log_edit.tpl (.../system_log_edit.tpl) (revision 16715)
+++ branches/5.2.x/core/admin_templates/logs/system_logs/system_log_edit.tpl (.../system_log_edit.tpl) (revision 16754)
@@ -56,22 +56,27 @@
font-size: 12px;
}
- .highlight-area {
+ div.highlight-area {
border: 1px solid black;
padding: 8px;
font-family: serif;
background-color: #F6F6F6;
overflow: auto;
+ margin-top: 4px;
}
.log_backtrace {
margin: 0;
padding-left: 25px;
}
- .log_backtrace div {
- margin: 4px 0;
+ div.expandable-area {
+ margin: 4px 0 4px 0;
}
+
+ div.expandable-area div.highlight-area:first-child {
+ margin-bottom: 4px;
+ }
@@ -84,13 +89,27 @@
-
+
- :
+
+
+
+
-
-
+
+ :
+
+
:
@@ -144,6 +163,11 @@
+
+
+
+
+
|
@@ -155,7 +179,7 @@
-
+
|
@@ -183,10 +207,10 @@
Index: branches/5.2.x/core/units/logs/system_logs/system_log_eh.php
===================================================================
diff -u -r16513 -r16754
--- branches/5.2.x/core/units/logs/system_logs/system_log_eh.php (.../system_log_eh.php) (revision 16513)
+++ branches/5.2.x/core/units/logs/system_logs/system_log_eh.php (.../system_log_eh.php) (revision 16754)
@@ -1,6 +1,6 @@
DeleteItems($event->Prefix, $event->Special, $ids);
}
}
+
+ /**
+ * Removes old code fragments.
+ *
+ * @param kEvent $event Event.
+ *
+ * @return void
+ */
+ protected function OnRotateCodeFragmentsScheduledTask(kEvent $event)
+ {
+ $id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
+ $table_name = $this->Application->getUnitOption($event->Prefix, 'TableName');
+
+ $sql = 'SELECT LogBacktrace, ' . $id_field . '
+ FROM ' . $table_name . '
+ WHERE LogTimestamp < ' . strtotime('-1 month') . ' AND LogCodeFragmentsRotated = 0
+ LIMIT 0,500';
+ $records = $this->Conn->GetColIterator($sql, $id_field);
+
+ foreach ( $records as $system_log_id => $trace ) {
+ if ( $trace ) {
+ $trace = unserialize($trace);
+
+ foreach ( $trace as $index => $trace_info ) {
+ if ( array_key_exists('code_fragment', $trace_info) ) {
+ unset($trace[$index]['code_fragment']);
+ }
+ }
+
+ $trace = serialize($trace);
+ }
+
+ $this->Conn->doUpdate(
+ array(
+ 'LogBacktrace' => $trace,
+ 'LogCodeFragment' => null,
+ 'LogCodeFragmentsRotated' => 1,
+ ),
+ $table_name,
+ $id_field . ' = ' . $system_log_id
+ );
+ }
+ }
+
}
Index: branches/5.2.x/core/kernel/utility/logger.php
===================================================================
diff -u -r16715 -r16754
--- branches/5.2.x/core/kernel/utility/logger.php (.../logger.php) (revision 16715)
+++ branches/5.2.x/core/kernel/utility/logger.php (.../logger.php) (revision 16754)
@@ -1,6 +1,6 @@
_logRecord['LogSourceFileLine'] = $line;
}
+ $code_fragment = $this->getCodeFragment(
+ $this->_logRecord['LogSourceFilename'],
+ $this->_logRecord['LogSourceFileLine']
+ );
+
+ if ( $code_fragment !== null ) {
+ $this->_logRecord['LogCodeFragment'] = $code_fragment;
+ }
+
return $this;
}
@@ -521,6 +530,14 @@
if ( isset($trace_info['args']) ) {
$trace[$trace_index]['args'] = $this->_implodeObjects($trace_info['args']);
}
+
+ if ( isset($trace_info['file'], $trace_info['line']) ) {
+ $code_fragment = $this->getCodeFragment($trace_info['file'], $trace_info['line']);
+
+ if ( $code_fragment !== null ) {
+ $trace[$trace_index]['code_fragment'] = $code_fragment;
+ }
+ }
}
$this->_logRecord['LogBacktrace'] = serialize($this->_removeObjectsFromTrace($trace));
@@ -529,6 +546,57 @@
}
/**
+ * Returns a code fragment.
+ *
+ * @param string $file Filename.
+ * @param integer $line Line.
+ *
+ * @return string|null
+ */
+ protected function getCodeFragment($file, $line)
+ {
+ static $path_filter_regexp;
+
+ // Lazy detect path filter regexp, because it's not available at construction time.
+ if ( $path_filter_regexp === null ) {
+ $application =& kApplication::Instance();
+ $path_filter_regexp = $application->ConfigValue('SystemLogCodeFragmentPathFilterRegExp');
+ }
+
+ if ( strpos($file, 'eval()\'d code') !== false
+ || ($path_filter_regexp && !preg_match($path_filter_regexp, $file))
+ ) {
+ return null;
+ }
+
+ $from_line = max(1, $line - 10);
+ $to_line = $line + 10;
+
+ // Prefix example: ">>> 5. " or " 5. ".
+ $prefix_length = 4 + strlen($to_line) + 2;
+
+ $cmd_parts = array(
+ 'sed',
+ '-n',
+ escapeshellarg($from_line . ',' . $to_line . 'p'),
+ escapeshellarg($file),
+ );
+ $command = implode(' ', $cmd_parts);
+
+ $ret = array();
+ $code_fragment = preg_replace('/(\r\n|\n|\r)$/', '', shell_exec($command), 1);
+
+ foreach ( explode("\n", $code_fragment) as $line_offset => $code_fragment_part ) {
+ $line_number = $from_line + $line_offset;
+ $line_indicator = $line_number == $line ? '>>> ' : ' ';
+
+ $ret[] = str_pad($line_indicator . $line_number . '.', $prefix_length) . $code_fragment_part;
+ }
+
+ return implode("\n", $ret);
+ }
+
+ /**
* Remove objects from trace, since before PHP 5.2.5 there wasn't possible to remove them initially
*
* @param Array $trace
Index: branches/5.2.x/core/units/logs/system_logs/system_log_tp.php
===================================================================
diff -u -r16513 -r16754
--- branches/5.2.x/core/units/logs/system_logs/system_log_tp.php (.../system_log_tp.php) (revision 16513)
+++ branches/5.2.x/core/units/logs/system_logs/system_log_tp.php (.../system_log_tp.php) (revision 16754)
@@ -1,6 +1,6 @@
prepareTagParams($params);
@@ -139,18 +140,49 @@
}
$block_params['has_args'] = isset($trace_info['args']);
+ $block_params['has_code_fragment'] = isset($trace_info['code_fragment']);
if ( $include_args ) {
$block_params['args'] = $block_params['has_args'] ? $this->highlightString(print_r($trace_info['args'], true)) : '';
}
+ if ( $include_code_fragment ) {
+ if ( $block_params['has_code_fragment'] ) {
+ $block_params['code_fragment'] = $this->highlightString($trace_info['code_fragment']);
+ }
+ else {
+ $block_params['code_fragment'] = '';
+ }
+ }
+
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
/**
+ * Prints a code fragment.
+ *
+ * @param array $params Tag params.
+ *
+ * @return string
+ */
+ protected function PrintCodeFragment(array $params)
+ {
+ /** @var kDBItem $object */
+ $object = $this->getObject($params);
+
+ $code_fragment = $object->GetDBField('LogCodeFragment');
+
+ if ( $code_fragment ) {
+ return $this->highlightString($code_fragment);
+ }
+
+ return '';
+ }
+
+ /**
* Prints backtrace record index
*
* @param Array $params
Index: branches/5.2.x/core/install/install_schema.sql
===================================================================
diff -u -r16748 -r16754
--- branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 16748)
+++ branches/5.2.x/core/install/install_schema.sql (.../install_schema.sql) (revision 16754)
@@ -447,14 +447,17 @@
LogBacktrace longtext,
LogSourceFilename varchar(255) NOT NULL DEFAULT '',
LogSourceFileLine int(11) DEFAULT NULL,
+ LogCodeFragment longtext,
+ LogCodeFragmentsRotated tinyint(4) NOT NULL DEFAULT '0',
LogProcessId bigint(20) unsigned DEFAULT NULL,
LogMemoryUsed bigint(20) unsigned NOT NULL,
LogUserData longtext NOT NULL,
LogNotificationStatus tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (LogId),
KEY LogLevel (LogLevel),
KEY LogType (LogType),
- KEY LogNotificationStatus (LogNotificationStatus)
+ KEY LogNotificationStatus (LogNotificationStatus),
+ KEY `TIMESTAMP_CODE_FRAGMENTS_ROTATED` (`LogTimestamp`,`LogCodeFragmentsRotated`) USING BTREE
);
CREATE TABLE SystemCache (
Index: branches/5.2.x/core/install/upgrades.sql
===================================================================
diff -u -r16748 -r16754
--- branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 16748)
+++ branches/5.2.x/core/install/upgrades.sql (.../upgrades.sql) (revision 16754)
@@ -2958,3 +2958,9 @@
ALTER TABLE Semaphores CHANGE MainIDs MainIDs TEXT NULL;
ALTER TABLE Users ADD KEY Email (Email);
+
+INSERT INTO SystemSettings VALUES(DEFAULT, 'SystemLogCodeFragmentPathFilterRegExp', '#(modules/custom|system/cache/modules/custom)/.*#', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsLogs', 'la_config_SystemLogCodeFragmentPathFilterRegExp', 'text', NULL, NULL, 65.05, 0, 1, NULL);
+ALTER TABLE SystemLog
+ ADD COLUMN `LogCodeFragment` longtext NULL AFTER `LogSourceFileLine`,
+ ADD COLUMN `LogCodeFragmentsRotated` tinyint(4) NOT NULL DEFAULT '0' AFTER `LogCodeFragment`;
+ALTER TABLE SystemLog ADD INDEX `TIMESTAMP_CODE_FRAGMENTS_ROTATED` (`LogTimestamp`,`LogCodeFragmentsRotated`) USING BTREE;
Index: branches/5.2.x/core/install/english.lang
===================================================================
diff -u -r16715 -r16754
--- branches/5.2.x/core/install/english.lang (.../english.lang) (revision 16715)
+++ branches/5.2.x/core/install/english.lang (.../english.lang) (revision 16754)
@@ -60,6 +60,7 @@
U2V0IFZhbHVl
U2hvdyBTdHJ1Y3R1cmU=
U3luY2hyb25pemU=
+ VG9nZ2xlIENvZGUuLi4=
VW5zZWxlY3Q=
VXA=
VXNl
@@ -211,6 +212,7 @@
VGVtcGxhdGUgZm9yIFNvZnQgTWFpbnRlbmFuY2U=
U1NMIEZ1bGwgVVJMIChodHRwczovL3d3dy5kb21haW4uY29tL3BhdGgp
VXNlIFN0aWNreSBHcmlkIFNlbGVjdGlvbg==
+ UmVjb3JkIGNvZGUgZnJhZ21lbnRzIGluICJTeXN0ZW0gTG9nIiBmb3IgdGhlc2UgcGF0aHMgKHJlZ2V4cCk=
U2VuZCBVc2VyLWRlZmluZWQgIlN5c3RlbSBMb2ciIG1lc3NhZ2VzIHRv
S2VlcCAiU3lzdGVtIExvZyIgZm9y
VGh1bWJuYWlsIEhlaWdodA==
@@ -1327,6 +1329,7 @@
QWRtaW4=
QWR2YW5jZWQ=
QWxs
+ QXJndW1lbnRz
QXV0by1SZWZyZXNo
QmFjayB1cCBoYXMgYmVlbiBjb21wbGV0ZWQuIFRoZSBiYWNrdXAgZmlsZSBpczo=
SW4tUG9ydGFsIGRvZXMgbm90IGhhdmUgYWNjZXNzIHRvIHdyaXRlIHRvIHRoaXMgZGlyZWN0b3J5
Index: branches/5.2.x/core/units/logs/system_logs/system_logs_config.php
===================================================================
diff -u -r16715 -r16754
--- branches/5.2.x/core/units/logs/system_logs/system_logs_config.php (.../system_logs_config.php) (revision 16715)
+++ branches/5.2.x/core/units/logs/system_logs/system_logs_config.php (.../system_logs_config.php) (revision 16754)
@@ -1,6 +1,6 @@
Array (
'system_log_notifications' => Array ('EventName' => 'OnSendNotifications', 'RunSchedule' => '0 * * * *'),
'rotate_system_logs' => Array ('EventName' => 'OnRotate', 'RunSchedule' => '0 0 * * *'),
+ 'rotate_system_log_code_fragments' => Array ('EventName' => 'OnRotateCodeFragmentsScheduledTask', 'RunSchedule' => '0 0 * * 0'),
),
'IDField' => 'LogId',
@@ -156,6 +157,13 @@
'LogBacktrace' => Array ('type' => 'string', 'default' => NULL),
'LogSourceFilename' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''),
'LogSourceFileLine' => Array ('type' => 'int', 'default' => NULL),
+ 'LogCodeFragment' => Array ('type' => 'string', 'default' => NULL),
+ 'LogCodeFragmentsRotated' => Array (
+ 'type' => 'int',
+ 'formatter' => 'kOptionsFormatter',
+ 'options' => Array (1 => 'la_Yes', 0 => 'la_No'), 'use_phrases' => 1,
+ 'not_null' => 1, 'default' => 0,
+ ),
'LogProcessId' => Array ('type' => 'int', 'default' => NULL),
'LogMemoryUsed' => Array ('type' => 'int', 'not_null' => 1, 'default' => 0),
'LogUserData' => Array ('type' => 'string', 'not_null' => 1, 'default' => ''),