10 use Monolog\Formatter\LineFormatter;
11 use Monolog\Handler\ErrorLogHandler;
13 use Monolog\Processor\MemoryPeakUsageProcessor;
14 use Monolog\Processor\MemoryUsageProcessor;
15 use Monolog\Processor\ProcessIdProcessor;
16 use Monolog\Processor\PsrLogMessageProcessor;
17 use Monolog\Processor\WebProcessor;
19 use Symfony\Component\Console\Input\InputInterface;
20 use Symfony\Component\Console\Output\OutputInterface;
27 class Logger extends \Monolog\Logger {
29 const CHANNEL =
'ELGG';
37 protected static array $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,
48 protected string $level = LogLevel::EMERGENCY;
50 protected array $disabled_stack = [];
61 $logger =
new static(self::CHANNEL);
63 if (\
Elgg\Application::isCli()) {
68 $app =
new CliApplication();
74 \
Elgg\Application::getStdErr(),
79 $formatter->allowInlineLineBreaks();
80 $formatter->ignoreEmptyContextAndExtra();
90 $handler->pushProcessor(
new WebProcessor());
92 $formatter =
new LineFormatter();
93 $formatter->allowInlineLineBreaks();
94 $formatter->ignoreEmptyContextAndExtra();
98 $handler->pushProcessor(
new MemoryUsageProcessor());
99 $handler->pushProcessor(
new MemoryPeakUsageProcessor());
100 $handler->pushProcessor(
new ProcessIdProcessor());
104 $handler->pushProcessor(
new PsrLogMessageProcessor());
109 $php_error_level = error_reporting();
111 $level = LogLevel::CRITICAL;
113 if (($php_error_level & E_NOTICE) == E_NOTICE) {
114 $level = LogLevel::NOTICE;
115 }
else if (($php_error_level & E_WARNING) == E_WARNING) {
116 $level = LogLevel::WARNING;
117 }
else if (($php_error_level & E_ERROR) == E_ERROR) {
118 $level = LogLevel::ERROR;
121 $logger->setLevel($level);
135 if (!in_array($level, self::$elgg_levels)) {
136 throw new InvalidArgumentException(
"Using the log level '{$level}' is not allowed. Use one of the \Psr\Log\LogLevel constants.");
149 public function setLevel(
string $level = LogLevel::EMERGENCY): void {
150 $this->assertLevel($level);
152 $this->level = $level;
163 public function getLevel(
bool $severity =
true): int|string {
164 return $severity ? array_search($this->level, self::$elgg_levels) : $this->level;
176 $this->assertLevel($level);
178 $severity = (int) array_search($level, self::$elgg_levels);
179 return $severity >= $this->getLevel();
187 $level = (string) $level;
188 $this->assertLevel($level);
190 if (
$message instanceof \Throwable) {
191 if (!isset(
$context[
'throwable']) && $this->isLoggable(LogLevel::NOTICE)) {
198 if (!empty($this->disabled_stack)) {
200 end($this->disabled_stack);
201 $key = key($this->disabled_stack);
202 $this->disabled_stack[
$key][] = [
210 if (!$this->isLoggable($level)) {
286 $this->disabled_stack[] = [];
297 return array_pop($this->disabled_stack);
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Handle system and PHP errors.
static getStdOut()
Load console output interface.
static getStdIn()
Load console input interface.
Wrapper for console application.
Exception thrown if an argument is not of the expected type.
Inject backtrace stack into the record.
log($level, $message, array $context=[])
{}
setLevel(string $level=LogLevel::EMERGENCY)
Set the logging level.
notice($message, array $context=[])
{}
isLoggable(string $level)
Check if a level is loggable under current logging level.
getLevel(bool $severity=true)
Get the current logging level severity.
emergency($message, array $context=[])
{}
alert($message, array $context=[])
{}
enable()
Restore logging and get record of log calls (after tests)
assertLevel(string $level)
Assert the given level.
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=[])
{}
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
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.