first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,99 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! Log Entry class
*
* This class is designed to hold log entries for either writing to an engine, or for
* supported engines, retrieving lists and building in memory (PHP based) search operations.
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
*/
class JLogEntry
{
/**
* Application responsible for log entry.
* @var string
* @since 11.1
*/
public $category;
/**
* The date the message was logged.
* @var JDate
* @since 11.1
*/
public $date;
/**
* Message to be logged.
* @var string
* @since 11.1
*/
public $message;
/**
* The priority of the message to be logged.
* @var string
* @since 11.1
* @see $priorities
*/
public $priority = JLog::INFO;
/**
* List of available log priority levels [Based on the Syslog default levels].
* @var array
* @since 11.1
*/
protected $priorities = array(
JLog::EMERGENCY,
JLog::ALERT,
JLog::CRITICAL,
JLog::ERROR,
JLog::WARNING,
JLog::NOTICE,
JLog::INFO,
JLog::DEBUG
);
/**
* Constructor
*
* @param string $message The message to log.
* @param string $priority Message priority based on {$this->priorities}.
* @param string $category Type of entry
* @param string $date Date of entry (defaults to now if not specified or blank)
*
* @since 11.1
*/
public function __construct($message, $priority = JLog::INFO, $category = '', $date = null)
{
$this->message = (string) $message;
// Sanitize the priority.
if (!in_array($priority, $this->priorities, true))
{
$priority = JLog::INFO;
}
$this->priority = $priority;
// Sanitize category if it exists.
if (!empty($category))
{
$this->category = (string) strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $category));
}
// Get the date as a JDate object.
$this->date = new JDate($date ? $date : 'now');
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,313 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! Log Class
*
* 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
* @subpackage Log
* @since 11.1
*/
class JLog
{
/**
* All log priorities.
* @var integer
* @since 11.1
*/
const ALL = 30719;
/**
* The system is unusable.
* @var integer
* @since 11.1
*/
const EMERGENCY = 1;
/**
* Action must be taken immediately.
* @var integer
* @since 11.1
*/
const ALERT = 2;
/**
* Critical conditions.
* @var integer
* @since 11.1
*/
const CRITICAL = 4;
/**
* Error conditions.
* @var integer
* @since 11.1
*/
const ERROR = 8;
/**
* Warning conditions.
* @var integer
* @since 11.1
*/
const WARNING = 16;
/**
* Normal, but significant condition.
* @var integer
* @since 11.1
*/
const NOTICE = 32;
/**
* Informational message.
* @var integer
* @since 11.1
*/
const INFO = 64;
/**
* Debugging message.
* @var integer
* @since 11.1
*/
const DEBUG = 128;
/**
* The global JLog instance.
* @var JLog
* @since 11.1
*/
protected static $instance;
/**
* Container for JLogLogger configurations.
* @var array
* @since 11.1
*/
protected $configurations = array();
/**
* Container for JLogLogger objects.
* @var array
* @since 11.1
*/
protected $loggers = array();
/**
* Lookup array for loggers.
* @var array
* @since 11.1
*/
protected $lookup = array();
/**
* Constructor.
*
* @since 11.1
*/
protected function __construct()
{
}
/**
* 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)
*
* @return void
*
* @since 11.1
*/
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.
if (!($entry instanceof JLogEntry))
{
$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
*
* @return void
*
* @since 11.1
*/
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'];
$options['callback'] = spl_object_hash($options['callback']);
}
// Generate a unique signature for the JLog instance based on its options.
$signature = md5(serialize($options));
// Now that the options array has been serialized, swap the callback back in
if (isset($callback))
{
$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.
*
* @return void
*
* @since 11.1
*/
public static function setInstance($instance)
{
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.
*
* @return void
*
* @since 11.1
* @throws RuntimeException
*/
protected function addLogEntry(JLogEntry $entry)
{
// 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']);
if (class_exists($class))
{
$this->loggers[$signature] = new $class($this->configurations[$signature]);
}
else
{
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.
*
* @since 11.1
*/
protected function findLoggers($priority, $category)
{
$loggers = array();
// Sanitize inputs.
$priority = (int) $priority;
$category = strtolower($category);
// 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 ($rules->exclude)
{
// 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))
{
$loggers[] = $signature;
}
}
else
{
// 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))
{
$loggers[] = $signature;
}
}
}
}
return $loggers;
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! Logger Base Class
*
* This class is used to be the basis of logger classes to allow for defined functions
* to exist regardless of the child class.
*
* @package Joomla.Platform
* @subpackage Log
* @since 12.2
*/
abstract class JLogLogger
{
/**
* Options array for the JLog instance.
* @var array
* @since 12.2
*/
protected $options = array();
/**
* @var array Translation array for JLogEntry priorities to text strings.
* @since 12.2
*/
protected $priorities = array(
JLog::EMERGENCY => 'EMERGENCY',
JLog::ALERT => 'ALERT',
JLog::CRITICAL => 'CRITICAL',
JLog::ERROR => 'ERROR',
JLog::WARNING => 'WARNING',
JLog::NOTICE => 'NOTICE',
JLog::INFO => 'INFO',
JLog::DEBUG => 'DEBUG');
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 12.2
*/
public function __construct(array &$options)
{
// Set the options for the class.
$this->options = & $options;
}
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return void
*
* @since 12.2
*/
abstract public function addEntry(JLogEntry $entry);
}
/**
* Deprecated class placeholder. You should use JLogLogger instead.
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
* @deprecated 13.3 (Platform) & 4.0 (CMS)
* @codeCoverageIgnore
*/
abstract class JLogger extends JLogLogger
{
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 11.1
* @deprecated 13.3
*/
public function __construct(array &$options)
{
JLog::add('JLogger is deprecated. Use JLogLogger instead.', JLog::WARNING, 'deprecated');
parent::__construct($options);
}
}

View File

@ -0,0 +1,68 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! Callback Log class
*
* This class allows logging to be handled by a callback function.
* This allows unprecedented flexibility in the way logging can be handled.
*
* @package Joomla.Platform
* @subpackage Log
* @since 12.2
*/
class JLogLoggerCallback extends JLogLogger
{
/**
* @var callable The function to call when an entry is added - should return True on success
* @since 12.2
*/
protected $callback;
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 12.2
*/
public function __construct(array &$options)
{
// Call the parent constructor.
parent::__construct($options);
// Throw an exception if there is not a valid callback
if (isset($this->options['callback']) && is_callable($this->options['callback']))
{
$this->callback = $this->options['callback'];
}
else
{
throw new JLogException(JText::_('JLogLoggerCallback created without valid callback function.'));
}
}
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return boolean True on success.
*
* @since 12.2
* @throws LogException
*/
public function addEntry(JLogEntry $entry)
{
// Pass the log entry to the callback function
call_user_func($this->callback, $entry);
}
}

View File

@ -0,0 +1,152 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! MySQL Database Log class
*
* This class is designed to output logs to a specific MySQL database table. Fields in this
* table are based on the Syslog style of log output. This is designed to allow quick and
* easy searching.
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
*/
class JLogLoggerDatabase extends JLogLogger
{
/**
* @var string The name of the database driver to use for connecting to the database.
* @since 11.1
*/
protected $driver = 'mysqli';
/**
* @var string The host name (or IP) of the server with which to connect for the logger.
* @since 11.1
*/
protected $host = '127.0.0.1';
/**
* @var string The database server user to connect as for the logger.
* @since 11.1
*/
protected $user = 'root';
/**
* @var string The password to use for connecting to the database server.
* @since 11.1
*/
protected $password = '';
/**
* @var string The name of the database table to use for the logger.
* @since 11.1
*/
protected $database = 'logging';
/**
* @var string The database table to use for logging entries.
* @since 11.1
*/
protected $table = 'jos_';
/**
* @var JDatabaseDriver The database driver object for the logger.
* @since 11.1
*/
protected $db;
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 11.1
*/
public function __construct(array &$options)
{
// Call the parent constructor.
parent::__construct($options);
// If both the database object and driver options are empty we want to use the system database connection.
if (empty($this->options['db_driver']))
{
$this->db = JFactory::getDbo();
$this->driver = null;
$this->host = null;
$this->user = null;
$this->password = null;
$this->database = null;
$this->prefix = null;
}
else
{
$this->db = null;
$this->driver = (empty($this->options['db_driver'])) ? 'mysqli' : $this->options['db_driver'];
$this->host = (empty($this->options['db_host'])) ? '127.0.0.1' : $this->options['db_host'];
$this->user = (empty($this->options['db_user'])) ? 'root' : $this->options['db_user'];
$this->password = (empty($this->options['db_pass'])) ? '' : $this->options['db_pass'];
$this->database = (empty($this->options['db_database'])) ? 'logging' : $this->options['db_database'];
$this->prefix = (empty($this->options['db_prefix'])) ? 'jos_' : $this->options['db_prefix'];
}
// The table name is independent of how we arrived at the connection object.
$this->table = (empty($this->options['db_table'])) ? '#__log_entries' : $this->options['db_table'];
}
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return void
*
* @since 11.1
*/
public function addEntry(JLogEntry $entry)
{
// Connect to the database if not connected.
if (empty($this->db))
{
$this->connect();
}
// Convert the date.
$entry->date = $entry->date->toSql(false, $this->db);
$this->db->insertObject($this->table, $entry);
}
/**
* Method to connect to the database server based on object properties.
*
* @return void
*
* @since 11.1
* @throws RuntimeException
*/
protected function connect()
{
// Build the configuration object to use for JDatabaseDriver.
$options = array(
'driver' => $this->driver,
'host' => $this->host,
'user' => $this->user,
'password' => $this->password,
'database' => $this->database,
'prefix' => $this->prefix);
$db = JDatabaseDriver::getInstance($options);
// Assign the database connector to the class.
$this->db = $db;
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla Echo logger class.
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
*/
class JLogLoggerEcho extends JLogLogger
{
/**
* @var string Value to use at the end of an echoed log entry to separate lines.
* @since 11.1
*/
protected $line_separator = "\n";
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 12.1
*/
public function __construct(array &$options)
{
parent::__construct($options);
if (!empty($this->options['line_separator']))
{
$this->line_separator = $this->options['line_separator'];
}
}
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return void
*
* @since 11.1
*/
public function addEntry(JLogEntry $entry)
{
echo $this->priorities[$entry->priority] . ': '
. $entry->message . (empty($entry->category) ? '' : ' [' . $entry->category . ']')
. $this->line_separator;
}
}

View File

@ -0,0 +1,268 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
jimport('joomla.filesystem.folder');
/**
* Joomla! Formatted Text File Log class
*
* This class is designed to use as a base for building formatted text files for output. By
* default it emulates the Syslog style format output. This is a disk based output format.
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
*/
class JLogLoggerFormattedtext extends JLogLogger
{
/**
* @var resource The file pointer for the log file.
* @since 11.1
*/
protected $file;
/**
* @var string The format for which each entry follows in the log file. All fields must be named
* in all caps and be within curly brackets eg. {FOOBAR}.
* @since 11.1
*/
protected $format = '{DATETIME} {PRIORITY} {CATEGORY} {MESSAGE}';
/**
* @var array The parsed fields from the format string.
* @since 11.1
*/
protected $fields = array();
/**
* @var string The full filesystem path for the log file.
* @since 11.1
*/
protected $path;
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 11.1
*/
public function __construct(array &$options)
{
// Call the parent constructor.
parent::__construct($options);
// The name of the text file defaults to 'error.php' if not explicitly given.
if (empty($this->options['text_file']))
{
$this->options['text_file'] = 'error.php';
}
// The name of the text file path defaults to that which is set in configuration if not explicitly given.
if (empty($this->options['text_file_path']))
{
$this->options['text_file_path'] = JFactory::getConfig()->get('log_path');
}
// False to treat the log file as a php file.
if (empty($this->options['text_file_no_php']))
{
$this->options['text_file_no_php'] = false;
}
// Build the full path to the log file.
$this->path = $this->options['text_file_path'] . '/' . $this->options['text_file'];
// Use the default entry format unless explicitly set otherwise.
if (!empty($this->options['text_entry_format']))
{
$this->format = (string) $this->options['text_entry_format'];
}
// Build the fields array based on the format string.
$this->parseFields();
}
/**
* Destructor.
*
* @since 11.1
*/
public function __destruct()
{
if (is_resource($this->file))
{
fclose($this->file);
}
}
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return boolean True on success.
*
* @since 11.1
* @throws RuntimeException
*/
public function addEntry(JLogEntry $entry)
{
// Initialise the file if not already done.
if (!is_resource($this->file))
{
$this->initFile();
}
// Set some default field values if not already set.
if (!isset($entry->clientIP))
{
// Check for proxies as well.
if (isset($_SERVER['REMOTE_ADDR']))
{
$entry->clientIP = $_SERVER['REMOTE_ADDR'];
}
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$entry->clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
elseif (isset($_SERVER['HTTP_CLIENT_IP']))
{
$entry->clientIP = $_SERVER['HTTP_CLIENT_IP'];
}
}
// If the time field is missing or the date field isn't only the date we need to rework it.
if ((strlen($entry->date) != 10) || !isset($entry->time))
{
// Get the date and time strings in GMT.
$entry->datetime = $entry->date->toISO8601();
$entry->time = $entry->date->format('H:i:s', false);
$entry->date = $entry->date->format('Y-m-d', false);
}
// Get a list of all the entry keys and make sure they are upper case.
$tmp = array_change_key_case(get_object_vars($entry), CASE_UPPER);
// Decode the entry priority into an English string.
$tmp['PRIORITY'] = $this->priorities[$entry->priority];
// Fill in field data for the line.
$line = $this->format;
foreach ($this->fields as $field)
{
$line = str_replace('{' . $field . '}', (isset($tmp[$field])) ? $tmp[$field] : '-', $line);
}
// Write the new entry to the file.
if (!fwrite($this->file, $line . "\n"))
{
throw new RuntimeException('Cannot write to log file.');
}
}
/**
* Method to generate the log file header.
*
* @return string The log file header
*
* @since 11.1
*/
protected function generateFileHeader()
{
$head = array();
// Build the log file header.
// If the no php flag is not set add the php die statement.
if (empty($this->options['text_file_no_php']))
{
// Blank line to prevent information disclose: https://bugs.php.net/bug.php?id=60677
$head[] = '#';
$head[] = '#<?php die(\'Forbidden.\'); ?>';
}
$head[] = '#Date: ' . gmdate('Y-m-d H:i:s') . ' UTC';
$head[] = '#Software: ' . JPlatform::getLongVersion();
$head[] = '';
// Prepare the fields string
$head[] = '#Fields: ' . strtolower(str_replace('}', '', str_replace('{', '', $this->format)));
$head[] = '';
return implode("\n", $head);
}
/**
* Method to initialise the log file. This will create the folder path to the file if it doesn't already
* exist and also get a new file header if the file doesn't already exist. If the file already exists it
* will simply open it for writing.
*
* @return void
*
* @since 11.1
* @throws RuntimeException
*/
protected function initFile()
{
// If the file doesn't already exist we need to create it and generate the file header.
if (!is_file($this->path))
{
// Make sure the folder exists in which to create the log file.
JFolder::create(dirname($this->path));
// Build the log file header.
$head = $this->generateFileHeader();
}
else
{
$head = false;
}
// Open the file for writing (append mode).
if (!$this->file = fopen($this->path, 'a'))
{
throw new RuntimeException('Cannot open file for writing log');
}
if ($head)
{
if (!fwrite($this->file, $head))
{
throw new RuntimeException('Cannot fput file for log');
}
}
}
/**
* Method to parse the format string into an array of fields.
*
* @return void
*
* @since 11.1
*/
protected function parseFields()
{
$this->fields = array();
$matches = array();
// Get all of the available fields in the format string.
preg_match_all("/{(.*?)}/i", $this->format, $matches);
// Build the parsed fields list based on the found fields.
foreach ($matches[1] as $match)
{
$this->fields[] = strtoupper($match);
}
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,58 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla MessageQueue logger class.
*
* This class is designed to output logs to a specific MySQL database table. Fields in this
* table are based on the Syslog style of log output. This is designed to allow quick and
* easy searching.
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
*/
class JLogLoggerMessagequeue extends JLogLogger
{
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return void
*
* @since 11.1
*/
public function addEntry(JLogEntry $entry)
{
switch ($entry->priority)
{
case JLog::EMERGENCY:
case JLog::ALERT:
case JLog::CRITICAL:
case JLog::ERROR:
JFactory::getApplication()->enqueueMessage($entry->message, 'error');
break;
case JLog::WARNING:
JFactory::getApplication()->enqueueMessage($entry->message, 'warning');
break;
case JLog::NOTICE:
JFactory::getApplication()->enqueueMessage($entry->message, 'notice');
break;
case JLog::INFO:
JFactory::getApplication()->enqueueMessage($entry->message, 'message');
break;
default:
// Ignore other priorities.
break;
}
}
}

View File

@ -0,0 +1,130 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! Syslog Log class
*
* This class is designed to call the PHP Syslog function call which is then sent to the
* system wide log system. For Linux/Unix based systems this is the syslog subsystem, for
* the Windows based implementations this can be found in the Event Log. For Windows,
* permissions may prevent PHP from properly outputting messages.
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
*/
class JLogLoggerSyslog extends JLogLogger
{
/**
* @var array Translation array for JLogEntry priorities to SysLog priority names.
* @since 11.1
*/
protected $priorities = array(
JLog::EMERGENCY => 'EMERG',
JLog::ALERT => 'ALERT',
JLog::CRITICAL => 'CRIT',
JLog::ERROR => 'ERR',
JLog::WARNING => 'WARNING',
JLog::NOTICE => 'NOTICE',
JLog::INFO => 'INFO',
JLog::DEBUG => 'DEBUG');
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 11.1
*/
public function __construct(array &$options)
{
// Call the parent constructor.
parent::__construct($options);
// Ensure that we have an identity string for the Syslog entries.
if (empty($this->options['sys_ident']))
{
$this->options['sys_ident'] = 'Joomla Platform';
}
// If the option to add the process id to Syslog entries is set use it, otherwise default to true.
if (isset($this->options['sys_add_pid']))
{
$this->options['sys_add_pid'] = (bool) $this->options['sys_add_pid'];
}
else
{
$this->options['sys_add_pid'] = true;
}
// If the option to also send Syslog entries to STDERR is set use it, otherwise default to false.
if (isset($this->options['sys_use_stderr']))
{
$this->options['sys_use_stderr'] = (bool) $this->options['sys_use_stderr'];
}
else
{
$this->options['sys_use_stderr'] = false;
}
// Build the Syslog options from our log object options.
$sysOptions = 0;
if ($this->options['sys_add_pid'])
{
$sysOptions = $sysOptions | LOG_PID;
}
if ($this->options['sys_use_stderr'])
{
$sysOptions = $sysOptions | LOG_PERROR;
}
// Default logging facility is LOG_USER for Windows compatibility.
$sysFacility = LOG_USER;
// If we have a facility passed in and we're not on Windows, reset it.
if (isset($this->options['sys_facility']) && !IS_WIN)
{
$sysFacility = $this->options['sys_facility'];
}
// Open the Syslog connection.
openlog((string) $this->options['sys_ident'], $sysOptions, $sysFacility);
}
/**
* Destructor.
*
* @since 11.1
*/
public function __destruct()
{
closelog();
}
/**
* Method to add an entry to the log.
*
* @param JLogEntry $entry The log entry object to add to the log.
*
* @return void
*
* @since 11.1
*/
public function addEntry(JLogEntry $entry)
{
// Generate the value for the priority based on predefined constants.
$priority = constant(strtoupper('LOG_' . $this->priorities[$entry->priority]));
// Send the entry to Syslog.
syslog($priority, '[' . $entry->category . '] ' . $entry->message);
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @package Joomla.Platform
* @subpackage Log
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Joomla! W3c Logging class
*
* This class is designed to build log files based on the W3c specification
* at: http://www.w3.org/TR/WD-logfile.html
*
* @package Joomla.Platform
* @subpackage Log
* @since 11.1
*/
class JLogLoggerW3c extends JLogLoggerFormattedtext
{
/**
* @var string The format which each entry follows in the log file. All fields must be
* named in all caps and be within curly brackets eg. {FOOBAR}.
* @since 11.1
*/
protected $format = '{DATE} {TIME} {PRIORITY} {CLIENTIP} {CATEGORY} {MESSAGE}';
/**
* Constructor.
*
* @param array &$options Log object options.
*
* @since 11.1
*/
public function __construct(array &$options)
{
// The name of the text file defaults to 'error.w3c.php' if not explicitly given.
if (empty($options['text_file']))
{
$options['text_file'] = 'error.w3c.php';
}
// Call the parent constructor.
parent::__construct($options);
}
}