1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-08 07:36:32 +02:00

Closes #5469 Added option to set the user when logging.

This commit is contained in:
camer0n
2025-04-11 18:42:34 -07:00
parent 5a040b64e2
commit 2f3b4a435b
2 changed files with 366 additions and 299 deletions

View File

@@ -24,6 +24,7 @@ if (!defined('e107_INIT'))
define('LOG_MESSAGE_NODISPLAY', 'nodisplay'); define('LOG_MESSAGE_NODISPLAY', 'nodisplay');
/** /**
* Admin logging class. * Admin logging class.
* *
@@ -42,13 +43,14 @@ class e_admin_log
*/ */
protected $_options = array('log_level' => 2, 'backtrace' => false,); protected $_options = array('log_level' => 2, 'backtrace' => false,);
protected $rldb = NULL; // Database used by logging routine protected $rldb = null; // Database used by logging routine
protected $_userData = null;
protected $logFile = null; protected $logFile = null;
/** /**
* Log messages * Log messages
*
* @var array * @var array
*/ */
protected $_messages; protected $_messages;
@@ -68,10 +70,11 @@ class e_admin_log
* Constructor. Sets up constants and overwrites default options where set. * Constructor. Sets up constants and overwrites default options where set.
* *
* @param array $options * @param array $options
* @return null * @return void
*/ */
public function __construct($options = array()) public function __construct($options = array())
{ {
if(!empty($options)) if(!empty($options))
{ {
foreach($options as $key => $val) foreach($options as $key => $val)
@@ -129,35 +132,56 @@ class e_admin_log
} }
/**
* Set the user ID and name for the next log entry
* @param int $user_id
* @param string $user_name
* @return e_admin_log
*/
public function setUser($user_id, $user_name='')
{
$this->_userData = array(
'user_id' => (int) $user_id,
'user_name' => !empty($user_name) ? e107::getParser()->toDB($user_name, true, false, 'no_html') : ''
);
return $this;
}
/** /**
* @deprecated * @deprecated
* BC Alias of add(); * BC Alias of add();
*/ */
public function log_event($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE, $event_code = '') public function log_event($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE, $event_code = '')
{ {
trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use add() instead.', E_USER_DEPRECATED); trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use add() instead.', E_USER_DEPRECATED);
return $this->add($event_title, $event_detail, $event_type, $event_code); return $this->add($event_title, $event_detail, $event_type, $event_code);
} }
/** /**
* Save all logs in the queue to the database and render any unhidden messages with the message handler. * Save all logs in the queue to the database and render any unhidden messages with the message handler.
* @see alias flushMessages() method below. *
* @param string $logTitle - title for log entry eg. 'PREF_01' * @param string $logTitle - title for log entry eg. 'PREF_01'
* @param int $logImportance [optional] default E_LOG_INFORMATIVE, E_LOG_NOTICE, E_LOG_WARNING, E_LOG_FATAL - passed directly to admin log * @param int $logImportance [optional] default E_LOG_INFORMATIVE, E_LOG_NOTICE, E_LOG_WARNING, E_LOG_FATAL - passed directly to admin log
* @param string $logEventCode [optional] - passed directly to admin log * @param string $logEventCode [optional] - passed directly to admin log
* @param string $mstack [optional] message stack passed to message handler * @param string $mstack [optional] message stack passed to message handler
* @param int LOG_TO_ADMIN|LOG_TO_ROLLING|LOG_TO_AUDIT * @param int LOG_TO_ADMIN|LOG_TO_ROLLING|LOG_TO_AUDIT
* @return \e_admin_log * @return \e_admin_log
* @see alias flushMessages() method below.
*/ */
public function save($logTitle, $logImportance = E_LOG_INFORMATIVE, $logEventCode = '', $mstack = false, $target = LOG_TO_ADMIN) public function save($logTitle, $logImportance = E_LOG_INFORMATIVE, $logEventCode = '', $mstack = false, $target = LOG_TO_ADMIN)
{ {
return $this->flushMessages($logTitle, $logImportance, $logEventCode, $mstack, $target); return $this->flushMessages($logTitle, $logImportance, $logEventCode, $mstack, $target);
} }
/** /**
* Add and Save an event into the admin, rolling or user log. * Add and Save an event into the admin, rolling or user log.
*
* @param string $event_title * @param string $event_title
* @param string|array $event_detail * @param string|array $event_detail
* @param integer $event_type [optional] Log level eg. E_LOG_INFORMATIVE, E_LOG_NOTICE, E_LOG_WARNING, E_LOG_FATAL * @param integer $event_type [optional] Log level eg. E_LOG_INFORMATIVE, E_LOG_NOTICE, E_LOG_WARNING, E_LOG_FATAL
@@ -178,6 +202,7 @@ class e_admin_log
*/ */
public function add($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE, $event_code = '', $target = LOG_TO_ADMIN, $userData = null) public function add($event_title, $event_detail, $event_type = E_LOG_INFORMATIVE, $event_code = '', $target = LOG_TO_ADMIN, $userData = null)
{ {
if(empty($event_code)) if(empty($event_code))
{ {
if(strlen($event_title) <= 12) if(strlen($event_title) <= 12)
@@ -203,22 +228,25 @@ class e_admin_log
} }
$this->addEvent($event_type, -1, $event_code, $event_title, $event_detail, FALSE, $target, $userData); $this->addEvent($event_type, -1, $event_code, $event_title, $event_detail, false, $target, $userData);
return $this; return $this;
} }
/** /**
* Enable/Disable the Rolling Log. * Enable/Disable the Rolling Log.
*
* @param $bool * @param $bool
*/ */
public function rollingLog($bool) public function rollingLog($bool)
{ {
$this->_roll_log_active = (bool) $bool; $this->_roll_log_active = (bool) $bool;
} }
/** /**
* Alias for deprecated e_log_event * Alias for deprecated e_log_event
*
* @param int $importance - importance of event - 0..4 or so * @param int $importance - importance of event - 0..4 or so
* @param mixed $source_call - either: string identifying calling file/routine * @param mixed $source_call - either: string identifying calling file/routine
* or: a number 0..9 identifying info to log from debug_backtrace() * or: a number 0..9 identifying info to log from debug_backtrace()
@@ -235,12 +263,13 @@ class e_admin_log
* *
* @return null * @return null
*/ */
public function addEvent($importance, $source_call, $eventcode = 'GEN', $event_title = 'Untitled', $explain = '', $finished = FALSE, $target_logs = LOG_TO_AUDIT, $userData=null ) public function addEvent($importance, $source_call, $eventcode = 'GEN', $event_title = 'Untitled', $explain = '', $finished = false, $target_logs = LOG_TO_AUDIT, $userData = null)
{ {
$e107 = e107::getInstance(); $e107 = e107::getInstance();
$tp = e107::getParser(); $tp = e107::getParser();
list($time_usec, $time_sec) = explode(' ', microtime(FALSE)); // Log event time immediately to minimise uncertainty list($time_usec, $time_sec) = explode(' ', microtime(false)); // Log event time immediately to minimise uncertainty
$time_usec = $time_usec * 1000000; $time_usec = $time_usec * 1000000;
if($this->rldb === null) // Better use our own db - don't know what else is going on if($this->rldb === null) // Better use our own db - don't know what else is going on
@@ -259,7 +288,7 @@ class e_admin_log
$userid = deftrue('USER') ? USERID : 0; $userid = deftrue('USER') ? USERID : 0;
$userstring = deftrue('USER') ? USERNAME : 'LAN_ANONYMOUS'; $userstring = deftrue('USER') ? USERNAME : 'LAN_ANONYMOUS';
$userIP = e107::getIPHandler()->getIP(FALSE); $userIP = e107::getIPHandler()->getIP(false);
if(!empty($userData['user_id'])) if(!empty($userData['user_id']))
{ {
@@ -402,8 +431,6 @@ class e_admin_log
); );
$this->rldb->insert('dblog', '0, ' . intval($time_sec) . ', ' . intval($time_usec) . ", '{$importance}', '{$eventcode}', {$userid}, '{$userstring}', '{$userIP}', '{$source_call}', '{$event_title}', '{$explain}' "); $this->rldb->insert('dblog', '0, ' . intval($time_sec) . ', ' . intval($time_usec) . ", '{$importance}', '{$eventcode}', {$userid}, '{$userstring}', '{$userIP}', '{$source_call}', '{$event_title}', '{$explain}' ");
// Now delete any old stuff // Now delete any old stuff
@@ -425,8 +452,9 @@ class e_admin_log
/** /**
* @deprecated - use add() method instead or addEvent() as a direct replacement. * @deprecated - use add() method instead or addEvent() as a direct replacement.
*/ */
public function e_log_event($importance, $source_call, $eventcode = 'GEN', $event_title = 'Untitled', $explain = '', $finished = FALSE, $target_logs = LOG_TO_AUDIT, $userData=null ) public function e_log_event($importance, $source_call, $eventcode = 'GEN', $event_title = 'Untitled', $explain = '', $finished = false, $target_logs = LOG_TO_AUDIT, $userData = null)
{ {
trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use add()->save() or addEvent() instead.', E_USER_DEPRECATED); trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use add()->save() or addEvent() instead.', E_USER_DEPRECATED);
return $this->addEvent($importance, $source_call, $eventcode, $event_title, $explain, $finished, $target_logs, $userData); return $this->addEvent($importance, $source_call, $eventcode, $event_title, $explain, $finished, $target_logs, $userData);
@@ -439,6 +467,7 @@ class e_admin_log
*/ */
public function setCurrentPlugin($plugdir) public function setCurrentPlugin($plugdir)
{ {
$this->_current_plugin = $plugdir; $this->_current_plugin = $plugdir;
return $this; return $this;
@@ -448,6 +477,7 @@ class e_admin_log
* USER AUDIT ENTRY * USER AUDIT ENTRY
*-------------------------------------- *--------------------------------------
* Log user-related events * Log user-related events
*
* @param string $event_type * @param string $event_type
* @param array|string $event_data is an array of data fields whose keys and values are logged (usually user data, but doesn't have to be - can add messages here) * @param array|string $event_data is an array of data fields whose keys and values are logged (usually user data, but doesn't have to be - can add messages here)
* @param int $id user-id * @param int $id user-id
@@ -458,6 +488,7 @@ class e_admin_log
*/ */
function user_audit($event_type, $event_data, $id = null, $u_name = '') function user_audit($event_type, $event_data, $id = null, $u_name = '')
{ {
list($time_usec, $time_sec) = explode(' ', microtime()); // Log event time immediately to minimise uncertainty list($time_usec, $time_sec) = explode(' ', microtime()); // Log event time immediately to minimise uncertainty
$time_usec = $time_usec * 1000000; $time_usec = $time_usec * 1000000;
@@ -469,7 +500,8 @@ class e_admin_log
$debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); $debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4);
$debug[0] = e_REQUEST_URI; $debug[0] = e_REQUEST_URI;
$this->addEvent(4, $debug[1]['file']. '|' .$debug[1]['function']. '@' .$debug[1]['line'], 'USERAUDIT', $title, $debug, FALSE); $this->addEvent(4, $debug[1]['file'] . '|' . $debug[1]['function'] . '@' . $debug[1]['line'], 'USERAUDIT', $title, $debug, false);
return false; return false;
} }
@@ -548,7 +580,6 @@ class e_admin_log
*/ */
/** /**
* Removes all events older than $days, or truncates the table if $days == false * Removes all events older than $days, or truncates the table if $days == false
* *
@@ -557,6 +588,7 @@ class e_admin_log
*/ */
public function purge_log_events($days) public function purge_log_events($days)
{ {
global $sql; global $sql;
if($days == false) if($days == false)
{ // $days is false, so truncate the log table { // $days is false, so truncate the log table
@@ -585,6 +617,7 @@ class e_admin_log
*/ */
function logArrayDiffs($new, $old, $event, $logNow = true) function logArrayDiffs($new, $old, $event, $logNow = true)
{ {
// $changes = array(); // $changes = array();
$changes = array_diff_recursive($new, $old); $changes = array_diff_recursive($new, $old);
@@ -600,16 +633,16 @@ class e_admin_log
$this->logMessage($changes, LOG_MESSAGE_NODISPLAY, E_MESSAGE_INFO); $this->logMessage($changes, LOG_MESSAGE_NODISPLAY, E_MESSAGE_INFO);
} }
return TRUE; return true;
} }
return FALSE; return false;
} }
/** /**
* Logs an entry with all the data from an array, one field per line. * Logs an entry with all the data from an array, one field per line.
* @deprecated Use e107::getLog()->addArray($arrayData)->save($event); *
* @param string $event - LAN define or string used as title in log * @param string $event - LAN define or string used as title in log
* @param array $target - data to be logged * @param array $target - data to be logged
* @param string $extra - if non-empty, it goes on the first line. * @param string $extra - if non-empty, it goes on the first line.
@@ -617,9 +650,11 @@ class e_admin_log
* If the $niceName array exists and has a definition, the 'nice Name' is displayed instead of the key name * If the $niceName array exists and has a definition, the 'nice Name' is displayed instead of the key name
* *
* @return null * @return null
* @deprecated Use e107::getLog()->addArray($arrayData)->save($event);
*/ */
public function logArrayAll($event, $target, $extra = '', $niceNames = NULL) public function logArrayAll($event, $target, $extra = '', $niceNames = null)
{ {
trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use e107::getLog()->addArray($arrayData)->save($event) instead.', E_USER_DEPRECATED); // no LAN trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use e107::getLog()->addArray($arrayData)->save($event) instead.', E_USER_DEPRECATED); // no LAN
if($extra == '' && $niceNames == null) if($extra == '' && $niceNames == null)
{ {
@@ -634,7 +669,7 @@ class e_admin_log
$logString = $extra . '[!br!]'; $logString = $extra . '[!br!]';
} }
$spacer = ''; $spacer = '';
$checkNice = ($niceNames != NULL) && is_array($niceNames); $checkNice = ($niceNames != null) && is_array($niceNames);
foreach($target as $k => $v) foreach($target as $k => $v)
{ {
if($checkNice && isset($niceNames[$k]['niceName'])) if($checkNice && isset($niceNames[$k]['niceName']))
@@ -668,7 +703,7 @@ class e_admin_log
* *
* @return e_admin_log * @return e_admin_log
*/ */
public function logMessage($text, $type = '', $logLevel = TRUE, $session = FALSE) public function logMessage($text, $type = '', $logLevel = true, $session = false)
{ {
if(is_array($text)) if(is_array($text))
@@ -679,6 +714,7 @@ class e_admin_log
{ {
$bt = debug_backtrace(true); $bt = debug_backtrace(true);
e107::getMessage()->addDebug('Log Message was empty: ' . print_a($bt[1], true)); e107::getMessage()->addDebug('Log Message was empty: ' . print_a($bt[1], true));
return $this; // changing to text will break chained methods. return $this; // changing to text will break chained methods.
} }
@@ -686,7 +722,7 @@ class e_admin_log
{ {
$type = E_MESSAGE_INFO; $type = E_MESSAGE_INFO;
} }
if($logLevel === TRUE) if($logLevel === true)
{ {
$logLevel = $type; $logLevel = $type;
} }
@@ -700,26 +736,28 @@ class e_admin_log
} }
/** /**
* @deprecated * @deprecated
* BC Alias for addSuccess(); * BC Alias for addSuccess();
*/ */
public function logSuccess($text, $message = true, $session = false) public function logSuccess($text, $message = true, $session = false)
{ {
trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use e107::getLog()->addSuccess($arrayData)->save($event) instead.', E_USER_DEPRECATED); // no LAN trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use e107::getLog()->addSuccess($arrayData)->save($event) instead.', E_USER_DEPRECATED); // no LAN
return $this->addSuccess($text, $message, $session); return $this->addSuccess($text, $message, $session);
} }
/** /**
* @deprecated * @deprecated
* BC Alias for addError(); * BC Alias for addError();
*/ */
public function logError($text, $message = true, $session = false) public function logError($text, $message = true, $session = false)
{ {
trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use e107::getLog()->addError($arrayData)->save($event) instead.', E_USER_DEPRECATED); // no LAN trigger_error('<b>' . __METHOD__ . ' is deprecated.</b> Use e107::getLog()->addError($arrayData)->save($event) instead.', E_USER_DEPRECATED); // no LAN
return $this->addError($text, $message, $session); return $this->addError($text, $message, $session);
} }
@@ -734,6 +772,7 @@ class e_admin_log
*/ */
public function addSuccess($text, $message = true, $session = false) public function addSuccess($text, $message = true, $session = false)
{ {
return $this->logMessage($text, ($message ? E_MESSAGE_SUCCESS : LOG_MESSAGE_NODISPLAY), E_MESSAGE_SUCCESS, $session); return $this->logMessage($text, ($message ? E_MESSAGE_SUCCESS : LOG_MESSAGE_NODISPLAY), E_MESSAGE_SUCCESS, $session);
} }
@@ -748,6 +787,7 @@ class e_admin_log
*/ */
public function addError($text, $message = true, $session = false) public function addError($text, $message = true, $session = false)
{ {
return $this->logMessage($text, ($message ? E_MESSAGE_ERROR : LOG_MESSAGE_NODISPLAY), E_MESSAGE_ERROR, $session); return $this->logMessage($text, ($message ? E_MESSAGE_ERROR : LOG_MESSAGE_NODISPLAY), E_MESSAGE_ERROR, $session);
} }
@@ -762,6 +802,7 @@ class e_admin_log
*/ */
public function addDebug($text, $message = true, $session = false) public function addDebug($text, $message = true, $session = false)
{ {
return $this->logMessage($text, ($message ? E_MESSAGE_DEBUG : LOG_MESSAGE_NODISPLAY), E_MESSAGE_DEBUG, $session); return $this->logMessage($text, ($message ? E_MESSAGE_DEBUG : LOG_MESSAGE_NODISPLAY), E_MESSAGE_DEBUG, $session);
} }
@@ -776,12 +817,14 @@ class e_admin_log
*/ */
public function addWarning($text, $message = true, $session = false) public function addWarning($text, $message = true, $session = false)
{ {
return $this->logMessage($text, ($message ? E_MESSAGE_WARNING : LOG_MESSAGE_NODISPLAY), E_MESSAGE_WARNING, $session); return $this->logMessage($text, ($message ? E_MESSAGE_WARNING : LOG_MESSAGE_NODISPLAY), E_MESSAGE_WARNING, $session);
} }
/** /**
* Add an array to the log queue * Add an array to the log queue
*
* @param $array * @param $array
* @param null $oldArray (optional) - when included, only the changes between the arrays is saved. * @param null $oldArray (optional) - when included, only the changes between the arrays is saved.
* @param string $type (optional) default: LOG_MESSAGE_NODISPLAY. or E_MESSAGE_WARNING, E_MESSAGE_DEBUG, E_MESSAGE_SUCCESS * @param string $type (optional) default: LOG_MESSAGE_NODISPLAY. or E_MESSAGE_WARNING, E_MESSAGE_DEBUG, E_MESSAGE_SUCCESS
@@ -790,6 +833,7 @@ class e_admin_log
*/ */
public function addArray($array, $oldArray = null, $type = LOG_MESSAGE_NODISPLAY, $session = false) public function addArray($array, $oldArray = null, $type = LOG_MESSAGE_NODISPLAY, $session = false)
{ {
if(is_array($oldArray)) if(is_array($oldArray))
{ {
$text = array_diff_recursive($array, $oldArray); // Located in core_functions.php $text = array_diff_recursive($array, $oldArray); // Located in core_functions.php
@@ -809,6 +853,7 @@ class e_admin_log
/** /**
* Return the last row added to the log table. * Return the last row added to the log table.
*
* @param int $type * @param int $type
* @return array|string * @return array|string
*/ */
@@ -831,6 +876,7 @@ class e_admin_log
} }
$query = 'SELECT * FROM #' . $table . ' ORDER BY dblog_id DESC LIMIT 1'; $query = 'SELECT * FROM #' . $table . ' ORDER BY dblog_id DESC LIMIT 1';
return e107::getDb()->retrieve($query); return e107::getDb()->retrieve($query);
} }
@@ -843,10 +889,12 @@ class e_admin_log
* @param int $logImportance - passed directly to admin log * @param int $logImportance - passed directly to admin log
* @param string $logEventCode - passed directly to admin log * @param string $logEventCode - passed directly to admin log
* @param string $mstack [optional] message stack passed to message handler * @param string $mstack [optional] message stack passed to message handler
* @param int $target - LOG_TO_ADMIN|LOG_TO_ROLLING|LOG_TO_AUDIT
* @return e_admin_log * @return e_admin_log
*/ */
public function flushMessages($logTitle, $logImportance = E_LOG_INFORMATIVE, $logEventCode = '', $mstack = false, $target = LOG_TO_ADMIN) public function flushMessages($logTitle, $logImportance = E_LOG_INFORMATIVE, $logEventCode = '', $mstack = false, $target = LOG_TO_ADMIN)
{ {
$mes = e107::getMessage(); $mes = e107::getMessage();
$resultTypes = array(E_MESSAGE_SUCCESS => 'Success', E_MESSAGE_ERROR => 'Fail'); // Add LANS here. Could add other codes $resultTypes = array(E_MESSAGE_SUCCESS => 'Success', E_MESSAGE_ERROR => 'Fail'); // Add LANS here. Could add other codes
@@ -854,10 +902,13 @@ class e_admin_log
$logString = ''; $logString = '';
foreach($this->_messages as $m) foreach($this->_messages as $m)
{ {
if ($m['loglevel'] !== FALSE) if($m['loglevel'] !== false)
{ {
$logString .= $separator; $logString .= $separator;
if ($m['loglevel'] == LOG_MESSAGE_NODISPLAY) { $logString .= ' '; } // Indent supplementary messages if($m['loglevel'] == LOG_MESSAGE_NODISPLAY)
{
$logString .= ' ';
} // Indent supplementary messages
// Not sure about next line - might want to log the <br /> as text, rather than it forcing a newline // Not sure about next line - might want to log the <br /> as text, rather than it forcing a newline
$logString .= strip_tags(str_replace(array('<br>', '<br/>', '<br />'), '[!br!]', $m['message'])); $logString .= strip_tags(str_replace(array('<br>', '<br/>', '<br />'), '[!br!]', $m['message']));
if(isset($resultTypes[$m['loglevel']])) if(isset($resultTypes[$m['loglevel']]))
@@ -879,21 +930,20 @@ class e_admin_log
} }
} }
} }
$this->add($logTitle, $logString, $logImportance, $logEventCode, $target); $this->add($logTitle, $logString, $logImportance, $logEventCode, $target, $this->_userData);
$this->_messages = array(); // Clear the memory for reuse $this->_messages = array(); // Clear the memory for reuse
$this->_userData = null; // Clear the user data to prevent reuse
return $this; return $this;
} }
/** /**
* Clear all messages in 'memory'. * Clear all messages in 'memory'.
*/ */
public function clear() public function clear()
{ {
$this->_messages = array(); $this->_messages = array();
return $this; return $this;
@@ -905,6 +955,7 @@ class e_admin_log
*/ */
private function saveToFile($logTitle = '', $append = false, $opts = array()) private function saveToFile($logTitle = '', $append = false, $opts = array())
{ {
if($this->logFile == null) if($this->logFile == null)
{ {
return null; return null;
@@ -930,7 +981,6 @@ class e_admin_log
$date = ($append == true) ? date('Y-m-d') : date('Y-m-d_H-i-s') . '_' . crc32($text); $date = ($append == true) ? date('Y-m-d') : date('Y-m-d_H-i-s') . '_' . crc32($text);
$dir = e_LOG; $dir = e_LOG;
if(empty($this->_current_plugin)) if(empty($this->_current_plugin))
@@ -976,6 +1026,7 @@ class e_admin_log
{ {
$this->_allMessages = array(); $this->_allMessages = array();
$this->_current_plugin = null; $this->_current_plugin = null;
return $this->logFile; return $this->logFile;
} }
@@ -990,11 +1041,10 @@ class e_admin_log
} }
/** /**
* Set and save accumulated log to a file. * Set and save accumulated log to a file.
* Use addDebug(), addError() or addSuccess() prior to executing. * Use addDebug(), addError() or addSuccess() prior to executing.
*
* @param string name without the extension. (ie. date prefix and .log suffix will be added automatically) * @param string name without the extension. (ie. date prefix and .log suffix will be added automatically)
* @param string Title for use inside the Log file * @param string Title for use inside the Log file
* @param boolean true = append to file, false = new file each save. * @param boolean true = append to file, false = new file each save.
@@ -1006,6 +1056,7 @@ class e_admin_log
$file = $this->saveToFile($logTitle, $append, $opts); $file = $this->saveToFile($logTitle, $append, $opts);
$this->logFile = null; $this->logFile = null;
return $file; return $file;
} }

View File

@@ -25,7 +25,7 @@
} }
catch(Exception $e) catch(Exception $e)
{ {
$this->assertTrue(false, "Couldn't load e_admin_log object"); $this::fail("Couldn't load e_admin_log object");
} }
$this->log->__construct(); $this->log->__construct();
@@ -63,9 +63,25 @@
$result = $this->log->getLastLog(); $result = $this->log->getLastLog();
$this->assertNotEmpty($result['dblog_eventcode']); $this::assertNotEmpty($result['dblog_eventcode']);
$this->assertSame('ADD_ARRAY', $result['dblog_eventcode']); $this::assertSame('ADD_ARRAY', $result['dblog_eventcode']);
$this->assertSame("Array[!br!]([!br!] [one] =&gt; two[!br!] [three] =&gt; four[!br!])[!br!]",$result['dblog_remarks']); $this::assertSame("Array[!br!]([!br!] [one] =&gt; two[!br!] [three] =&gt; four[!br!])[!br!]",$result['dblog_remarks']);
}
public function testSetUser()
{
$arr = array('one'=>'two', 'three'=>'four');
$this->log->addArray($arr)->setUser(5, 'testuser')->save('ADD_W_USER');
$result = $this->log->getLastLog();
$this::assertNotEmpty($result['dblog_eventcode']);
$this::assertSame('ADD_W_USER', $result['dblog_eventcode']);
$this::assertEquals(5, $result['dblog_user_id']);
} }
/* /*
@@ -101,10 +117,10 @@
$result = $this->log->getLastLog(); $result = $this->log->getLastLog();
$this->assertNotEmpty($result['dblog_eventcode']); $this::assertNotEmpty($result['dblog_eventcode']);
$this->assertSame('TEST', $result['dblog_eventcode']); $this::assertSame('TEST', $result['dblog_eventcode']);
$this->assertSame("Array[!br!]([!br!] [one] =&gt; test[!br!] [two] =&gt; testing[!br!])[!br!]", $result['dblog_remarks']); $this::assertSame("Array[!br!]([!br!] [one] =&gt; test[!br!] [two] =&gt; testing[!br!])[!br!]", $result['dblog_remarks']);
} }
/* /*
@@ -129,20 +145,20 @@
$this->log->add('testAdd Title', "testAdd Message", E_LOG_INFORMATIVE, 'TEST_ADD'); $this->log->add('testAdd Title', "testAdd Message", E_LOG_INFORMATIVE, 'TEST_ADD');
$result = $this->log->getLastLog(); $result = $this->log->getLastLog();
$this->assertNotEmpty($result['dblog_eventcode']); $this::assertNotEmpty($result['dblog_eventcode']);
$this->assertSame('TEST_ADD', $result['dblog_eventcode']); $this::assertSame('TEST_ADD', $result['dblog_eventcode']);
$this->assertSame("testAdd Message", $result['dblog_remarks']); $this::assertSame("testAdd Message", $result['dblog_remarks']);
$this->assertSame('testAdd Title', $result['dblog_title']); $this::assertSame('testAdd Title', $result['dblog_title']);
// add to rolling log (dblog) // add to rolling log (dblog)
$this->log->rollingLog(true); $this->log->rollingLog(true);
$this->log->add('Rolling Title', "Rolling Message", E_LOG_INFORMATIVE, 'TEST_ROLL', LOG_TO_ROLLING); $this->log->add('Rolling Title', "Rolling Message", E_LOG_INFORMATIVE, 'TEST_ROLL', LOG_TO_ROLLING);
$result = $this->log->getLastLog(LOG_TO_ROLLING); $result = $this->log->getLastLog(LOG_TO_ROLLING);
$this->assertNotEmpty($result['dblog_eventcode']); $this::assertNotEmpty($result['dblog_eventcode']);
$this->assertSame('TEST_ROLL', $result['dblog_eventcode']); $this::assertSame('TEST_ROLL', $result['dblog_eventcode']);
$this->assertSame("Rolling Message", $result['dblog_remarks']); $this::assertSame("Rolling Message", $result['dblog_remarks']);
$this->log->rollingLog(false); $this->log->rollingLog(false);