1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Log
5 *
6 * @copyright Copyright (C) 2005 - 2017 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 * @since 11.1
19 */
20 class JLogEntry
21 {
22 /**
23 * Application responsible for log entry.
24 * @var string
25 * @since 11.1
26 */
27 public $category;
28
29 /**
30 * The date the message was logged.
31 * @var JDate
32 * @since 11.1
33 */
34 public $date;
35
36 /**
37 * Message to be logged.
38 * @var string
39 * @since 11.1
40 */
41 public $message;
42
43 /**
44 * The priority of the message to be logged.
45 * @var string
46 * @since 11.1
47 * @see JLogEntry::$priorities
48 */
49 public $priority = JLog::INFO;
50
51 /**
52 * List of available log priority levels [Based on the Syslog default levels].
53 * @var array
54 * @since 11.1
55 */
56 protected $priorities = array(
57 JLog::EMERGENCY,
58 JLog::ALERT,
59 JLog::CRITICAL,
60 JLog::ERROR,
61 JLog::WARNING,
62 JLog::NOTICE,
63 JLog::INFO,
64 JLog::DEBUG,
65 );
66
67 /**
68 * Call stack and back trace of the logged call.
69 * @var array
70 * @since 12.3
71 */
72 public $callStack = array();
73
74 /**
75 * Constructor
76 *
77 * @param string $message The message to log.
78 * @param int $priority Message priority based on {$this->priorities}.
79 * @param string $category Type of entry
80 * @param string $date Date of entry (defaults to now if not specified or blank)
81 *
82 * @since 11.1
83 */
84 public function __construct($message, $priority = JLog::INFO, $category = '', $date = null)
85 {
86 $this->message = (string) $message;
87
88 // Sanitize the priority.
89 if (!in_array($priority, $this->priorities, true))
90 {
91 $priority = JLog::INFO;
92 }
93
94 $this->priority = $priority;
95
96 // Sanitize category if it exists.
97 if (!empty($category))
98 {
99 $this->category = (string) strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $category));
100 }
101
102 // Get the current call stack and back trace (without args to save memory).
103 $this->callStack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
104
105 // Get the date as a JDate object.
106 $this->date = new JDate($date ? $date : 'now');
107 }
108 }
109