Source for file log.php
Documentation is available at log.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* This class hooks into the global log configuration settings to allow for user configured
* logging events to be sent to where the user wishes them to be sent. On high load sites
* Syslog is probably the best (pure PHP function), then the text file based loggers (CSV, W3c
* or plain Formattedtext) and finally MySQL offers the most features (e.g. rapid searching)
* but will incur a performance hit due to INSERT being issued.
* @package Joomla.Platform
* The system is unusable.
* Action must be taken immediately.
* Normal, but significant condition.
* The global JLog instance.
protected static $instance;
* Container for JLogLogger configurations.
* Container for JLogLogger objects.
* Lookup array for loggers.
* Method to add an entry to the log.
* @param mixed $entry The JLogEntry object to add to the log or the message for a new JLogEntry object.
* @param integer $priority Message priority.
* @param string $category Type of entry
* @param string $date Date of entry (defaults to now if not specified or blank)
public static function add($entry, $priority =
self::INFO, $category =
'', $date =
null)
// Automatically instantiate the singleton object if not already done.
if (empty(self::$instance))
self::setInstance(new JLog);
// If the entry object isn't a JLogEntry object let's make one.
$entry =
new JLogEntry((string)
$entry, $priority, $category, $date);
self::$instance->addLogEntry($entry);
* Add a logger to the JLog instance. Loggers route log entries to the correct files/systems to be logged.
* @param array $options The object configuration array.
* @param integer $priorities Message priority
* @param array $categories Types of entry
* @param boolean $exclude If true, all categories will be logged except those in the $categories array
public static function addLogger(array $options, $priorities =
self::ALL, $categories =
array(), $exclude =
false)
// Automatically instantiate the singleton object if not already done.
if (empty(self::$instance))
self::setInstance(new JLog);
// The default logger is the formatted text log file.
if (empty($options['logger']))
$options['logger'] =
'formattedtext';
$options['logger'] =
strtolower($options['logger']);
// Special case - if a Closure object is sent as the callback (in case of JLogLoggerCallback)
// Closure objects are not serializable so swap it out for a unique id first then back again later
if (isset
($options['callback']) &&
is_a($options['callback'], 'closure'))
$callback =
$options['callback'];
// Generate a unique signature for the JLog instance based on its options.
// Now that the options array has been serialized, swap the callback back in
$options['callback'] =
$callback;
// Register the configuration if it doesn't exist.
if (empty(self::$instance->configurations[$signature]))
self::$instance->configurations[$signature] =
$options;
self::$instance->lookup[$signature] = (object)
array(
'priorities' =>
$priorities,
'categories' =>
array_map('strtolower', (array)
$categories),
'exclude' => (bool)
$exclude);
* Returns a reference to the a JLog object, only creating it if it doesn't already exist.
* Note: This is principally made available for testing and internal purposes.
* @param JLog $instance The logging object instance to be used by the static methods.
if (($instance instanceof
JLog) ||
$instance ===
null)
self::$instance =
& $instance;
* Method to add an entry to the appropriate loggers.
* @param JLogEntry $entry The JLogEntry object to send to the loggers.
* @throws RuntimeException
// Find all the appropriate loggers based on priority and category for the entry.
$loggers =
$this->findLoggers($entry->priority, $entry->category);
foreach ((array)
$loggers as $signature)
// Attempt to instantiate the logger object if it doesn't already exist.
if (empty($this->loggers[$signature]))
$class =
'JLogLogger' .
ucfirst($this->configurations[$signature]['logger']);
throw
new RuntimeException('Unable to create a JLogLogger instance: ' .
$class);
// Add the entry to the logger.
$this->loggers[$signature]->addEntry(clone($entry));
* Method to find the loggers to use based on priority and category values.
* @param integer $priority Message priority.
* @param string $category Type of entry
* @return array The array of loggers to use for the given priority and category values.
$priority = (int)
$priority;
// Let's go iterate over the loggers and get all the ones we need.
foreach ((array)
$this->lookup as $signature =>
$rules)
// Check to make sure the priority matches the logger.
if ($priority & $rules->priorities)
// If either there are no set categories or the category (including the empty case) is not in the list of excluded categories, add this logger.
if (empty($rules->categories) ||
!in_array($category, $rules->categories))
// If either there are no set categories (meaning all) or the specific category is set, add this logger.
if (empty($category) ||
empty($rules->categories) ||
in_array($category, $rules->categories))
Documentation generated on Tue, 19 Nov 2013 15:07:24 +0100 by phpDocumentor 1.4.3