Elgg
Version 5.0
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
Elgg
Logger
ElggLogFormatter.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Elgg\Logger
;
4
5
use
Elgg\Exceptions\DatabaseException
;
6
use
Monolog\Formatter\LineFormatter
;
7
11
class
ElggLogFormatter
extends
LineFormatter {
12
16
public
function
format
(array $record): string {
17
18
$context
=
elgg_extract
(
'context'
, $record, []);
19
$exception
=
elgg_extract
(
'exception'
,
$context
);
20
21
if
(
$exception
instanceof \Throwable) {
22
$timestamp
= isset(
$exception
->timestamp) ? (int)
$exception
->timestamp : time();
23
24
$dt
= new \DateTime();
25
$dt
->setTimestamp(
$timestamp
);
26
$record[
'datetime'
] =
$dt
;
27
28
$eol = PHP_EOL;
29
$message
=
"Exception at time {$timestamp}:{$eol}{$exception->getMessage()}{$eol}"
;
30
$record[
'message'
] = preg_replace(
'~\R~u'
, $eol,
$message
);
31
32
if
(
$exception
instanceof
DatabaseException
) {
33
$record[
'context'
][
'sql'
] =
$exception
->getQuery();
34
$record[
'context'
][
'params'
] =
$exception
->getParameters();
35
}
36
37
unset($record[
'context'
][
'exception'
]);
38
}
39
40
return
parent::format($record);
41
}
42
}
$context
$context
Definition:
add.php:8
Elgg\Logger\ElggLogFormatter
Custom log formatter.
Definition:
ElggLogFormatter.php:11
LineFormatter
$message
$message
Definition:
set_maintenance_mode.php:7
$timestamp
$timestamp
Definition:
date.php:36
Elgg\Logger
Definition:
BacktraceProcessor.php:3
DatabaseException
elgg_extract
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition:
elgglib.php:254
$dt
$dt
Definition:
time.php:71
Elgg\Logger\ElggLogFormatter\format
format(array $record)
{}
Definition:
ElggLogFormatter.php:16
Elgg\Exceptions\DatabaseException
A generic parent class for database exceptions.
Definition:
DatabaseException.php:10
$exception
$exception
Definition:
error.php:15
Generated on Thu Sep 28 2023 00:00:19 for Elgg by
1.8.11