Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
entry.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Log
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Joomla! Log Entry class
14  *
15  * This class is designed to hold log entries for either writing to an engine, or for
16  * supported engines, retrieving lists and building in memory (PHP based) search operations.
17  *
18  * @package Joomla.Platform
19  * @subpackage Log
20  * @since 11.1
21  */
22 class JLogEntry
23 {
24  /**
25  * Application responsible for log entry.
26  * @var string
27  * @since 11.1
28  */
29  public $category;
30 
31  /**
32  * The date the message was logged.
33  * @var JDate
34  * @since 11.1
35  */
36  public $date;
37 
38  /**
39  * Message to be logged.
40  * @var string
41  * @since 11.1
42  */
43  public $message;
44 
45  /**
46  * The priority of the message to be logged.
47  * @var string
48  * @since 11.1
49  * @see JLogEntry::$priorities
50  */
51  public $priority = JLog::INFO;
52 
53  /**
54  * List of available log priority levels [Based on the Syslog default levels].
55  * @var array
56  * @since 11.1
57  */
58  protected $priorities = array(
65  JLog::INFO,
67  );
68 
69  /**
70  * Constructor
71  *
72  * @param string $message The message to log.
73  * @param string $priority Message priority based on {$this->priorities}.
74  * @param string $category Type of entry
75  * @param string $date Date of entry (defaults to now if not specified or blank)
76  *
77  * @since 11.1
78  */
79  public function __construct($message, $priority = JLog::INFO, $category = '', $date = null)
80  {
81  $this->message = (string) $message;
82 
83  // Sanitize the priority.
84  if (!in_array($priority, $this->priorities, true))
85  {
86  $priority = JLog::INFO;
87  }
88  $this->priority = $priority;
89 
90  // Sanitize category if it exists.
91  if (!empty($category))
92  {
93  $this->category = (string) strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $category));
94  }
95 
96  // Get the date as a JDate object.
97  $this->date = new JDate($date ? $date : 'now');
98  }
99 }