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();
102 if (
$output->isVeryVerbose()) {
108 $handler->pushProcessor(
new WebProcessor());
111 $formatter->allowInlineLineBreaks();
112 $formatter->ignoreEmptyContextAndExtra();
116 $handler->pushProcessor(
new MemoryUsageProcessor());
117 $handler->pushProcessor(
new MemoryPeakUsageProcessor());
118 $handler->pushProcessor(
new ProcessIdProcessor());
122 $handler->pushProcessor(
new PsrLogMessageProcessor());
139 if (!is_string($level) || !in_array($level, self::$elgg_levels)) {
140 $level_value = $level;
141 if ($level ===
false) {
142 $level_value =
'false';
145 $this->warning(
"Deprecated in 6.1: Using the log level '{$level_value}' has been deprecated. Use the \Psr\Log\LogLevel constants.");
152 if (array_key_exists($level, self::$legacy_levels)) {
153 $level = self::$legacy_levels[$level];
154 if ($level ===
false) {
160 if (array_key_exists($level, self::$elgg_levels)) {
161 $level = self::$elgg_levels[$level];
164 if (!in_array($level, self::$elgg_levels)) {
182 if (!isset($level)) {
183 $php_error_level = error_reporting();
185 $level = LogLevel::CRITICAL;
187 if (($php_error_level & E_NOTICE) == E_NOTICE) {
188 $level = LogLevel::NOTICE;
189 }
else if (($php_error_level & E_WARNING) == E_WARNING) {
190 $level = LogLevel::WARNING;
191 }
else if (($php_error_level & E_ERROR) == E_ERROR) {
192 $level = LogLevel::ERROR;
196 $this->level = $this->normalizeLevel($level);
209 return array_search($this->level, self::$elgg_levels);
223 $level = $this->normalizeLevel($level);
225 $severity = array_search($level, self::$elgg_levels);
226 if (!$this->getLevel() || $severity < $this->getLevel()) {
238 $level = $this->normalizeLevel($level);
240 if (!empty($this->disabled_stack)) {
242 end($this->disabled_stack);
243 $key = key($this->disabled_stack);
244 $this->disabled_stack[
$key][] = [
252 if (!$this->isLoggable($level)) {
324 $this->warning(
'Deprecated in 6.3: ' . __METHOD__ .
' has been deprecated use ->error()');
326 $this->log(LogLevel::ERROR,
$data);
342 $this->disabled_stack[] = [];
353 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