LogEntry.php
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Log;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Date\Date;
/**
* 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.
*
* @since 1.7.0
*/
class LogEntry
{
/**
* Application responsible for log entry.
* @var string
* @since 1.7.0
*/
public $category;
/**
* The message context.
*
* @var array
* @since 3.8.0
*/
public $context;
/**
* The date the message was logged.
* @var Date
* @since 1.7.0
*/
public $date;
/**
* Message to be logged.
* @var string
* @since 1.7.0
*/
public $message;
/**
* The priority of the message to be logged.
* @var string
* @since 1.7.0
* @see LogEntry::$priorities
*/
public $priority = Log::INFO;
/**
* List of available log priority levels [Based on the Syslog default levels].
* @var array
* @since 1.7.0
*/
protected $priorities = array(
Log::EMERGENCY,
Log::ALERT,
Log::CRITICAL,
Log::ERROR,
Log::WARNING,
Log::NOTICE,
Log::INFO,
Log::DEBUG,
);
/**
* Call stack and back trace of the logged call.
* @var array
* @since 3.1.4
*/
public $callStack = array();
/**
* Constructor
*
* @param string $message The message to log.
* @param int $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)
* @param array $context An optional array with additional message context.
*
* @since 1.7.0
*/
public function __construct($message, $priority = Log::INFO, $category = '', $date = null, array $context = array())
{
$this->message = (string) $message;
// Sanitize the priority.
if (!in_array($priority, $this->priorities, true))
{
$priority = Log::INFO;
}
$this->priority = $priority;
$this->context = $context;
// Sanitize category if it exists.
if (!empty($category))
{
$this->category = (string) strtolower(preg_replace('/[^A-Z0-9_\.-]/i', '', $category));
}
// Get the current call stack and back trace (without args to save memory).
$this->callStack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
// Get the date as a Date object.
$this->date = new Date($date ? $date : 'now');
}
}