[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Log/ -> LogEntry.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2011 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Log;
  11  
  12  use Joomla\CMS\Date\Date;
  13  use Joomla\CMS\Filesystem\Path;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Joomla! Log Entry class
  21   *
  22   * This class is designed to hold log entries for either writing to an engine, or for
  23   * supported engines, retrieving lists and building in memory (PHP based) search operations.
  24   *
  25   * @since  1.7.0
  26   */
  27  class LogEntry
  28  {
  29      /**
  30       * Application responsible for log entry.
  31       *
  32       * @var    string
  33       * @since  1.7.0
  34       */
  35      public $category;
  36  
  37      /**
  38       * The message context.
  39       *
  40       * @var    array
  41       * @since  3.8.0
  42       */
  43      public $context;
  44  
  45      /**
  46       * The date the message was logged.
  47       *
  48       * @var    Date
  49       * @since  1.7.0
  50       */
  51      public $date;
  52  
  53      /**
  54       * Message to be logged.
  55       *
  56       * @var    string
  57       * @since  1.7.0
  58       */
  59      public $message;
  60  
  61      /**
  62       * The priority of the message to be logged.
  63       *
  64       * @var    string
  65       * @since  1.7.0
  66       * @see    LogEntry::$priorities
  67       */
  68      public $priority = Log::INFO;
  69  
  70      /**
  71       * List of available log priority levels [Based on the Syslog default levels].
  72       *
  73       * @var    array
  74       * @since  1.7.0
  75       */
  76      protected $priorities = array(
  77          Log::EMERGENCY,
  78          Log::ALERT,
  79          Log::CRITICAL,
  80          Log::ERROR,
  81          Log::WARNING,
  82          Log::NOTICE,
  83          Log::INFO,
  84          Log::DEBUG,
  85      );
  86  
  87      /**
  88       * Call stack and back trace of the logged call.
  89       * @var    array
  90       * @since  3.1.4
  91       */
  92      public $callStack = array();
  93  
  94      /**
  95       * Constructor
  96       *
  97       * @param   string  $message   The message to log.
  98       * @param   int     $priority  Message priority based on {$this->priorities}.
  99       * @param   string  $category  Type of entry
 100       * @param   string  $date      Date of entry (defaults to now if not specified or blank)
 101       * @param   array   $context   An optional array with additional message context.
 102       *
 103       * @since   1.7.0
 104       * @change  3.10.7  If the message contains a full path, the root path (JPATH_ROOT) is removed from it
 105       *          to avoid any full path disclosure. Before 3.10.7, the path was propagated as provided.
 106       */
 107      public function __construct($message, $priority = Log::INFO, $category = '', $date = null, array $context = array())
 108      {
 109          $this->message = Path::removeRoot((string) $message);
 110  
 111          // Sanitize the priority.
 112          if (!\in_array($priority, $this->priorities, true)) {
 113              $priority = Log::INFO;
 114          }
 115  
 116          $this->priority = $priority;
 117          $this->context  = $context;
 118  
 119          // Sanitize category if it exists.
 120          if (!empty($category)) {
 121              $this->category = (string) strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $category));
 122          }
 123  
 124          // Get the current call stack and back trace (without args to save memory).
 125          $this->callStack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
 126  
 127          // Get the date as a Date object.
 128          $this->date = new Date($date ?: 'now');
 129      }
 130  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer