Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803820
D410.id1018.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, Feb 26, 8:58 AM
Size
2 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 8:58 AM (10 h, 49 m)
Engine
blob
Format
Raw Data
Handle
576544
Attached To
D410: INP-1807 - Use dedicated connection for "kLogger" class
D410.id1018.diff
View Options
Index: core/kernel/utility/logger.php
===================================================================
--- core/kernel/utility/logger.php
+++ core/kernel/utility/logger.php
@@ -150,6 +150,13 @@
const LNS_SENT = 2;
/**
+ * Database connection used for logging.
+ *
+ * @var kDBConnection
+ */
+ protected $dbStorage;
+
+ /**
* List of error/exception handlers
*
* @var Array
@@ -221,6 +228,8 @@
{
parent::__construct();
+ $this->dbStorage = $this->getDBStorage();
+
$system_config = kUtil::getSystemConfig();
$this->_debugMode = $this->Application->isDebugMode();
@@ -241,6 +250,24 @@
}
/**
+ * Create separate connection for logging purposes.
+ *
+ * @return kDBConnection
+ */
+ protected function getDBStorage()
+ {
+ $system_config = new kSystemConfig(true);
+ $vars = $system_config->getData();
+ $db_class = $this->Application->isDebugMode() ? 'kDBConnectionDebug' : 'kDBConnection';
+
+ // Can't use "kApplication::makeClass", because class factory isn't initialized at this point.
+ $db = new $db_class(SQL_TYPE, array($this, 'handleSQLError'), 'logger');
+ $db->setup($vars);
+
+ return $db;
+ }
+
+ /**
* Sets state of the logged (enabled/user-only/disabled)
*
* @param $new_state
@@ -768,11 +795,11 @@
$this->_logRecord['LogDate'] = adodb_date('Y-m-d H:i:s');
if ( $storage_medium == self::LS_AUTOMATIC ) {
- $storage_medium = $this->Conn->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
+ $storage_medium = $this->dbStorage->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
}
if ( $storage_medium == self::LS_DATABASE ) {
- $result = $this->Conn->doInsert($this->_logRecord, TABLE_PREFIX . 'SystemLog');
+ $result = $this->dbStorage->doInsert($this->_logRecord, TABLE_PREFIX . 'SystemLog');
}
elseif ( $storage_medium == self::LS_DISK ) {
$result = $this->_saveToFile(RESTRICTED . '/system.log');
@@ -823,13 +850,13 @@
public function delete($unique_id, $storage_medium = self::LS_AUTOMATIC)
{
if ( $storage_medium == self::LS_AUTOMATIC ) {
- $storage_medium = $this->Conn->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
+ $storage_medium = $this->dbStorage->connectionOpened() ? self::LS_DATABASE : self::LS_DISK;
}
if ( $storage_medium == self::LS_DATABASE ) {
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'SystemLog
WHERE LogUniqueId = ' . $unique_id;
- $this->Conn->Query($sql);
+ $this->dbStorage->Query($sql);
}
elseif ( $storage_medium == self::LS_DISK ) {
// TODO: no way to delete a line from a file
Event Timeline
Log In to Comment