/
LogEntry.php
188 lines (170 loc) · 4.65 KB
/
LogEntry.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
namespace Concrete\Core\Logging;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\User\User;
use Monolog\Logger as Monolog;
class LogEntry
{
/**
* Gets the level of the log.
*
* @return string
*/
public function getLevel()
{
return $this->level;
}
/**
* Gets the name of the logging level.
*
* @return string
*/
public function getLevelName()
{
return Monolog::getLevelName($this->level);
}
/**
* Gets the name of the logging level.
*
* @return string
*/
public function getLevelDisplayName()
{
return Levels::getLevelDisplayName($this->level);
}
/**
* Gets the message of the log.
*
* @return string
*/
public function getMessage()
{
return $this->message;
}
/**
* Gets the channel of the log.
*
* @return string
*/
public function getChannel()
{
return $this->channel;
}
/**
* Gets the channel name of the logging level.
*
* @return string
*/
public function getChannelDisplayName()
{
return Channels::getChannelDisplayName($this->channel);
}
/**
* Gets the id of the log.
*
* @return int
*/
public function getID()
{
return $this->logID;
}
/**
* Gets the HTML code for the icon of the logging level.
*
* @return string
*/
public function getLevelIcon()
{
switch ($this->getLevel()) {
case Monolog::EMERGENCY:
return '<i class="text-danger fa fa-fire launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
case Monolog::CRITICAL:
return '<i class="text-danger fa fa-ambulance launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
case Monolog::ALERT:
return '<i class="text-danger fa fa-exclamation-circle launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
case Monolog::ERROR:
return '<i class="text-danger fa fa-flag launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
case Monolog::WARNING:
return '<i class="text-warning fa fa-warning launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
case Monolog::NOTICE:
return '<i class="text-success fa fa-leaf launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
case Monolog::INFO:
return '<i class="text-info fa fa-info-circle launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
case Monolog::DEBUG:
return '<i class="text-info fa fa-cog launch-tooltip" title="' . $this->getLevelDisplayName() . '"></i>';
}
}
/**
* Gets the user id of the user that caused the log.
*
* @return int
*/
public function getUserID()
{
return $this->uID;
}
/**
* Gets the user object of the user that caused the log.
*
* @return \Concrete\Core\User\User|null
*/
public function getUserObject()
{
if ($this->getUserID()) {
$u = User::getByUserID($this->getUserID());
if (is_object($u)) {
return $u;
}
}
}
/**
* Gets the formatted time of the log timestamp.
*
* @return string
*/
public function getDisplayTimestamp()
{
$app = Application::getFacadeApplication();
$dh = $app->make('helper/date'); /* @var $dh \Concrete\Core\Localization\Service\Date */
return $dh->formatDateTime($this->time, true, true);
}
/**
* Gets the timestamp of the log.
*
* @return string
*/
public function getTimestamp()
{
return $this->time;
}
/**
* Gets the log object from its id.
*
* @param int $logID Id of the log
*
* @return LogEntry|null
*/
public static function getByID($logID)
{
$app = Application::getFacadeApplication();
$db = $app->make('database')->connection();
$row = $db->fetchAssoc('select * from Logs where logID = ?', [$logID]);
if ($row) {
$obj = new static();
$obj = array_to_object($obj, $row);
return $obj;
}
}
/**
* Deletes the log entry.
*/
public function delete()
{
$app = Application::getFacadeApplication();
$db = $app->make('database')->connection();
$logID = $this->getID();
if (!empty($logID)) {
$db->delete('Logs', ['logID' => $logID]);
}
}
}