Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1050562
D521.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Jul 2, 11:01 PM
Size
3 KB
Mime Type
text/x-diff
Expires
Thu, Jul 3, 11:01 PM (11 h, 3 m)
Engine
blob
Format
Raw Data
Handle
678792
Attached To
D521: INP-1910 - Allow specifying upcoming System Log record defaults
D521.diff
View Options
Index: core/kernel/application.php
===================================================================
--- core/kernel/application.php
+++ core/kernel/application.php
@@ -3157,6 +3157,8 @@
return $log->write();
}
+ $this->_logger->takeSnapshot();
+
return $log;
}
Index: core/kernel/utility/logger.php
===================================================================
--- core/kernel/utility/logger.php
+++ core/kernel/utility/logger.php
@@ -181,6 +181,13 @@
protected $_logRecord = Array ();
/**
+ * Snapshot data, representing object properties used for log record creation.
+ *
+ * @var array
+ */
+ protected $snapshotData = array();
+
+ /**
* Maximal level of a message, that can be logged
*
* @var int
@@ -326,6 +333,8 @@
*/
public function prepare($message = '', $code = null)
{
+ $changed_snapshot_data = $this->getChangedSnapshot();
+
$this->_logRecord = Array (
'LogUniqueId' => kUtil::generateId(),
'LogMessage' => $message,
@@ -356,10 +365,89 @@
$this->_logRecord['IpAddress'] = $this->Application->getClientIp();
}
+ if ( $changed_snapshot_data ) {
+ $this->restoreSnapshot($changed_snapshot_data);
+ }
+
return $this;
}
/**
+ * Returns a snapshot based on changes made from a last saved snapshot.
+ *
+ * @return array
+ */
+ protected function getChangedSnapshot()
+ {
+ if ( !$this->snapshotData ) {
+ return array();
+ }
+
+ $ret = array();
+ $new_snapshot_data = $this->buildSnapshot();
+
+ foreach ( $this->snapshotData as $property_name => $old_property_value ) {
+ $new_property_value = $new_snapshot_data[$property_name];
+
+ if ( is_array($old_property_value) ) {
+ $changes = array_diff_assoc($new_property_value, $old_property_value);
+
+ if ( $changes ) {
+ $ret[$property_name] = $changes;
+ }
+ }
+ elseif ( $new_property_value !== $old_property_value ) {
+ $ret[$property_name] = $new_property_value;
+ }
+ }
+
+ return $ret;
+ }
+
+ /**
+ * Takes a snapshot based on the object properties.
+ *
+ * @return void
+ */
+ public function takeSnapshot()
+ {
+ $this->snapshotData = $this->buildSnapshot();
+ }
+
+ /**
+ * Builds a snapshot based on the object properties.
+ *
+ * @return array
+ */
+ protected function buildSnapshot()
+ {
+ return array(
+ '_logRecord' => $this->_logRecord,
+ 'requestDataRequired' => $this->requestDataRequired,
+ 'sessionDataRequired' => $this->sessionDataRequired,
+ );
+ }
+
+ /**
+ * Restores the snapshot.
+ *
+ * @param array $snapshot_data Snapshot data.
+ *
+ * @return void
+ */
+ protected function restoreSnapshot(array $snapshot_data)
+ {
+ foreach ( $snapshot_data as $property_name => $property_value ) {
+ if ( is_array($property_value) ) {
+ $this->{$property_name} = array_merge($this->{$property_name}, $property_value);
+ }
+ else {
+ $this->{$property_name} = $property_value;
+ }
+ }
+ }
+
+ /**
* Sets one or more fields of log record
*
* @param string|Array $field_name
@@ -840,6 +928,8 @@
*/
public function write($storage_medium = self::LS_AUTOMATIC, $check_origin = false)
{
+ $this->snapshotData = array();
+
if ( $check_origin && isset($this->_logRecord['LogSourceFilename']) ) {
$origin_allowed = self::isErrorOriginAllowed($this->_logRecord['LogSourceFilename']);
}
Event Timeline
Log In to Comment