API15:JLog/addEntry
From Joomla! Documentation
Template:Description:JLog/addEntry
Syntax
addEntry($entry)
| Parameter Name | Default Value | Description |
|---|---|---|
| $entry |
Defined in
libraries/joomla/error/log.php
Importing
jimport( 'joomla.error.log' );
Source Body
function addEntry($entry)
{
// Set some default field values if not already set.
$date =& JFactory::getDate();
if (!isset ($entry['date'])) {
$entry['date'] = $date->toFormat("%Y-%m-%d");
}
if (!isset ($entry['time'])) {
$entry['time'] = $date->toFormat("%H:%M:%S");
}
if (!isset ($entry['c-ip'])) {
$entry['c-ip'] = $_SERVER['REMOTE_ADDR'];
}
// Ensure that the log entry keys are all uppercase
$entry = array_change_key_case($entry, CASE_UPPER);
// Find all fields in the format string
$fields = array ();
$regex = "/{(.*?)}/i";
preg_match_all($regex, $this->_format, $fields);
// Fill in the field data
$line = $this->_format;
for ($i = 0; $i < count($fields[0]); $i++)
{
$line = str_replace($fields[0][$i], (isset ($entry[$fields[1][$i]])) ? $entry[$fields[1][$i]] : "-", $line);
}
// Write the log entry line
if ($this->_openLog())
{
if (!fputs($this->_file, "\n" . $line)) {
return false;
}
} else {
return false;
}
return true;
}
[Edit See Also] Template:SeeAlso:JLog/addEntry
Examples
<CodeExamplesForm />