ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
Log.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use Sabre\DAV\Exception\NotFound;
24use Sabre\DAV\Exception\NotAuthenticated;
25use Sabre\DAV\Exception\Locked;
26use Sabre\DAV\Exception\ConflictingLock;
27use Sabre\DAV\ServerPlugin;
28use Sabre\DAV\Server;
29use Override;
30
34class Log extends ServerPlugin
35{
36 public function __construct(
37 private bool $enable_debugging,
38 ) {
39 }
40
41 private ?\ilLogger $logger = null;
42 private const string EVENT_TYPE_EXCEPTION = 'exception';
43 private array $ignore_exceptions = [
44 NotFound::class,
45 NotAuthenticated::class,
46 Locked::class,
47 ConflictingLock::class,
48 ];
49
50 #[Override]
51 public function initialize(Server $server): void
52 {
53 $server->on(self::EVENT_TYPE_EXCEPTION, fn() => $this->handleException(func_get_arg(0)));
54
55 // TODO: remove service locator usage
56 global $DIC;
57 $this->logger ??= $DIC->logger()->webdav();
58
59 if ($this->enable_debugging) {
60 $this->ignore_exceptions = [];
61 }
62 }
63
64 private function handleException(\Throwable $e): void
65 {
66 foreach ($this->ignore_exceptions as $ignore_exception) {
67 if ($e instanceof $ignore_exception) {
68 return;
69 }
70 }
71
72 $called_by = $e->getTrace()[0] ?? null;
73 if ($called_by && isset($called_by['class'], $called_by['function'])) {
74 $this->logger->write(
75 'WEBDAV: Exception in ' . $called_by['class'] . '::' . $called_by['function'] . ' - ' . $e->getMessage(
76 ),
77 );
78 } else {
79 $this->logger->write(
80 'WEBDAV: Uncaught exception - ' . $e->getMessage(),
81 );
82 }
83 }
84
85}
ilLogger $logger
Definition: Log.php:41
__construct(private bool $enable_debugging,)
Definition: Log.php:36
array $ignore_exceptions
Definition: Log.php:43
handleException(\Throwable $e)
Definition: Log.php:64
const string EVENT_TYPE_EXCEPTION
Definition: Log.php:42
initialize(Server $server)
Definition: Log.php:51
Component logger with individual log levels by component id.
global $DIC
Definition: shib_login.php:26
$server
Definition: shib_login.php:28