10 use Monolog\Handler\ErrorLogHandler;
12 use Monolog\Processor\MemoryPeakUsageProcessor;
13 use Monolog\Processor\MemoryUsageProcessor;
14 use Monolog\Processor\ProcessIdProcessor;
15 use Monolog\Processor\PsrLogMessageProcessor;
16 use Monolog\Processor\WebProcessor;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Output\OutputInterface;
26 class Logger extends \Monolog\Logger {
28 const CHANNEL =
'ELGG';
36 protected static $elgg_levels = [
38 100 => LogLevel::DEBUG,
39 200 => LogLevel::INFO,
40 250 => LogLevel::NOTICE,
41 300 => LogLevel::WARNING,
42 400 => LogLevel::ERROR,
43 500 => LogLevel::CRITICAL,
44 550 => LogLevel::ALERT,
45 600 => LogLevel::EMERGENCY,
52 protected static $legacy_levels = [
54 'INFO' => LogLevel::INFO,
55 'NOTICE' => LogLevel::NOTICE,
56 'WARNING' => LogLevel::WARNING,
57 'ERROR' => LogLevel::ERROR,
68 protected $disabled_stack = [];
79 $logger =
new static(self::CHANNEL);
81 if (\
Elgg\Application::isCli()) {
86 $app =
new CliApplication();
92 \
Elgg\Application::getStdErr(),
97 $formatter->allowInlineLineBreaks();
98 $formatter->ignoreEmptyContextAndExtra();
106 $handler->pushProcessor(
new WebProcessor());
109 $formatter->allowInlineLineBreaks();
110 $formatter->ignoreEmptyContextAndExtra();
114 $handler->pushProcessor(
new MemoryUsageProcessor());
115 $handler->pushProcessor(
new MemoryPeakUsageProcessor());
116 $handler->pushProcessor(
new ProcessIdProcessor());
120 $handler->pushProcessor(
new PsrLogMessageProcessor());
137 if (!is_string($level) || !in_array($level, self::$elgg_levels)) {
138 $level_value = $level;
139 if ($level ===
false) {
140 $level_value =
'false';
143 $this->warning(
"Deprecated in 6.1: Using the log level '{$level_value}' has been deprecated. Use the \Psr\Log\LogLevel constants.");
150 if (array_key_exists($level, self::$legacy_levels)) {
151 $level = self::$legacy_levels[$level];
152 if ($level ===
false) {
158 if (array_key_exists($level, self::$elgg_levels)) {
159 $level = self::$elgg_levels[$level];
162 if (!in_array($level, self::$elgg_levels)) {
180 if (!isset($level)) {
181 $php_error_level = error_reporting();
183 $level = LogLevel::CRITICAL;
185 if (($php_error_level & E_NOTICE) == E_NOTICE) {
186 $level = LogLevel::NOTICE;
187 }
else if (($php_error_level & E_WARNING) == E_WARNING) {
188 $level = LogLevel::WARNING;
189 }
else if (($php_error_level & E_ERROR) == E_ERROR) {
190 $level = LogLevel::ERROR;
194 $this->level = $this->normalizeLevel($level);
207 return array_search($this->level, self::$elgg_levels);
221 $level = $this->normalizeLevel($level);
223 $severity = array_search($level, self::$elgg_levels);
224 if (!$this->getLevel() || $severity < $this->getLevel()) {
236 $level = $this->normalizeLevel($level);
238 if (!empty($this->disabled_stack)) {
240 end($this->disabled_stack);
241 $key = key($this->disabled_stack);
242 $this->disabled_stack[
$key][] = [
250 if (!$this->isLoggable($level)) {
321 $this->log(LogLevel::ERROR,
$data);
337 $this->disabled_stack[] = [];
348 return array_pop($this->disabled_stack);
if(! $entity instanceof \ElggUser) $data
Handle system and PHP errors.
static getStdOut()
Load console output interface.
static getStdIn()
Load console input interface.
Wrapper for console application.
Inject backtrace stack into the record.
dump($data)
Dump data to log.
log($level, $message, array $context=[])
{}
notice($message, array $context=[])
{}
normalizeLevel($level=null)
Normalizes legacy string or numeric representation of the level to LogLevel strings.
getLevel($severity=true)
Get the current logging level severity.
emergency($message, array $context=[])
{}
alert($message, array $context=[])
{}
isLoggable($level)
Check if a level is loggable under current logging level.
enable()
Restore logging and get record of log calls (after tests)
debug($message, array $context=[])
{}
error($message, array $context=[])
{}
static factory(?InputInterface $input=null, ?OutputInterface $output=null)
Build a new logger.
critical($message, array $context=[])
{}
info($message, array $context=[])
{}
setLevel($level=null)
Set the logging level.
warning($message, array $context=[])
{}
disable()
Temporarily disable logging and capture logs (before tests)
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key