Enable Discovery debug logging for production troubleshooting

- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
This commit is contained in:
2025-08-11 20:13:26 +02:00
parent 59fd3dd3b1
commit 55a330b223
3683 changed files with 2956207 additions and 16948 deletions

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Framework\Logging\Handlers;
@@ -57,7 +58,7 @@ class ConsoleHandler implements LogHandler
}
// Optional: Debug-Modus-Check nur in CLI
if ($this->debugOnly && !filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN)) {
if ($this->debugOnly && ! filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN)) {
return false;
}
@@ -109,6 +110,7 @@ class ConsoleHandler implements LogHandler
public function setMinLevel(LogLevel|int $level): self
{
$this->minLevel = $level instanceof LogLevel ? $level : LogLevel::fromValue($level);
return $this;
}
@@ -118,6 +120,7 @@ class ConsoleHandler implements LogHandler
public function setOutputFormat(string $format): self
{
$this->outputFormat = $format;
return $this;
}
}

View File

@@ -1,11 +1,14 @@
<?php
declare(strict_types=1);
namespace App\Framework\Logging\Handlers;
use App\Framework\Core\PathProvider;
use App\Framework\Logging\LogHandler;
use App\Framework\Logging\LogLevel;
use App\Framework\Logging\LogRecord;
use App\Framework\Logging\LogRotator;
/**
* Handler für die Ausgabe von Log-Einträgen in Dateien.
@@ -32,6 +35,16 @@ class FileHandler implements LogHandler
*/
private int $fileMode;
/**
* @var LogRotator|null Log-Rotator für automatische Rotation
*/
private ?LogRotator $rotator = null;
/**
* @var PathProvider|null PathProvider für die Auflösung von Pfaden
*/
private ?PathProvider $pathProvider = null;
/**
* Erstellt einen neuen FileHandler
*
@@ -39,17 +52,29 @@ class FileHandler implements LogHandler
* @param LogLevel|int $minLevel Minimales Level, ab dem dieser Handler aktiv wird
* @param string $outputFormat Format für die Ausgabe
* @param int $fileMode Datei-Modi für die Log-Datei
* @param LogRotator|null $rotator Optional: Log-Rotator für automatische Rotation
* @param PathProvider|null $pathProvider Optional: PathProvider für die Auflösung von Pfaden
*/
public function __construct(
string $logFile,
LogLevel|int $minLevel = LogLevel::DEBUG,
string $outputFormat = '[{timestamp}] [{level_name}] {request_id}{channel}{message}',
int $fileMode = 0644
int $fileMode = 0644,
?LogRotator $rotator = null,
?PathProvider $pathProvider = null
) {
$this->pathProvider = $pathProvider;
// Pfad auflösen, falls PathProvider vorhanden
if ($this->pathProvider !== null && ! str_starts_with($logFile, '/')) {
$logFile = $this->pathProvider->resolvePath($logFile);
}
$this->logFile = $logFile;
$this->minLevel = $minLevel instanceof LogLevel ? $minLevel : LogLevel::fromValue($minLevel);
$this->outputFormat = $outputFormat;
$this->fileMode = $fileMode;
$this->rotator = $rotator;
// Stelle sicher, dass das Verzeichnis existiert
$this->ensureDirectoryExists(dirname($logFile));
@@ -90,6 +115,11 @@ class FileHandler implements LogHandler
// Formatierte Ausgabe erstellen
$output = strtr($this->outputFormat, $values) . PHP_EOL;
// Prüfe Rotation vor dem Schreiben
if ($this->rotator !== null) {
$this->rotator->rotateIfNeeded($this->logFile);
}
// In die Datei schreiben
$this->write($output);
@@ -122,7 +152,7 @@ class FileHandler implements LogHandler
*/
private function ensureDirectoryExists(string $dir): void
{
if (!file_exists($dir)) {
if (! file_exists($dir)) {
mkdir($dir, 0777, true);
}
}
@@ -133,6 +163,7 @@ class FileHandler implements LogHandler
public function setMinLevel(LogLevel|int $level): self
{
$this->minLevel = $level instanceof LogLevel ? $level : LogLevel::fromValue($level);
return $this;
}
@@ -142,6 +173,7 @@ class FileHandler implements LogHandler
public function setOutputFormat(string $format): self
{
$this->outputFormat = $format;
return $this;
}
@@ -150,8 +182,14 @@ class FileHandler implements LogHandler
*/
public function setLogFile(string $logFile): self
{
// Pfad auflösen, falls PathProvider vorhanden
if ($this->pathProvider !== null && ! str_starts_with($logFile, '/')) {
$logFile = $this->pathProvider->resolvePath($logFile);
}
$this->logFile = $logFile;
$this->ensureDirectoryExists(dirname($logFile));
return $this;
}
}

View File

@@ -1,8 +1,10 @@
<?php
declare(strict_types=1);
namespace App\Framework\Logging\Handlers;
use App\Framework\Core\PathProvider;
use App\Framework\Logging\LogHandler;
use App\Framework\Logging\LogLevel;
use App\Framework\Logging\LogRecord;
@@ -28,18 +30,32 @@ class JsonFileHandler implements LogHandler
*/
private array $includedFields;
/**
* @var PathProvider|null PathProvider für die Auflösung von Pfaden
*/
private ?PathProvider $pathProvider = null;
/**
* Erstellt einen neuen JsonFileHandler
*
* @param string $logFile Pfad zur Log-Datei
* @param LogLevel|int $minLevel Minimales Level, ab dem dieser Handler aktiv wird
* @param array|null $includedFields Liste der Felder, die in der JSON-Ausgabe enthalten sein sollen (null = alle)
* @param PathProvider|null $pathProvider Optional: PathProvider für die Auflösung von Pfaden
*/
public function __construct(
string $logFile,
LogLevel|int $minLevel = LogLevel::INFO,
?array $includedFields = null
?array $includedFields = null,
?PathProvider $pathProvider = null
) {
$this->pathProvider = $pathProvider;
// Pfad auflösen, falls PathProvider vorhanden
if ($this->pathProvider !== null && ! str_starts_with($logFile, '/')) {
$logFile = $this->pathProvider->resolvePath($logFile);
}
$this->logFile = $logFile;
$this->minLevel = $minLevel instanceof LogLevel ? $minLevel : LogLevel::fromValue($minLevel);
@@ -74,7 +90,7 @@ class JsonFileHandler implements LogHandler
$data = $record->toArray();
// Nur die gewünschten Felder behalten
if (!empty($this->includedFields)) {
if (! empty($this->includedFields)) {
$data = array_intersect_key($data, array_flip($this->includedFields));
}
@@ -102,7 +118,7 @@ class JsonFileHandler implements LogHandler
*/
private function ensureDirectoryExists(string $dir): void
{
if (!file_exists($dir)) {
if (! file_exists($dir)) {
mkdir($dir, 0777, true);
}
}
@@ -113,6 +129,7 @@ class JsonFileHandler implements LogHandler
public function setMinLevel(LogLevel|int $level): self
{
$this->minLevel = $level instanceof LogLevel ? $level : LogLevel::fromValue($level);
return $this;
}
@@ -122,6 +139,7 @@ class JsonFileHandler implements LogHandler
public function setIncludedFields(array $fields): self
{
$this->includedFields = $fields;
return $this;
}
@@ -130,8 +148,14 @@ class JsonFileHandler implements LogHandler
*/
public function setLogFile(string $logFile): self
{
// Pfad auflösen, falls PathProvider vorhanden
if ($this->pathProvider !== null && ! str_starts_with($logFile, '/')) {
$logFile = $this->pathProvider->resolvePath($logFile);
}
$this->logFile = $logFile;
$this->ensureDirectoryExists(dirname($logFile));
return $this;
}
}

View File

@@ -1,8 +1,9 @@
<?php
declare(strict_types=1);
namespace App\Framework\Logging\Handlers;
use App\Framework\Database\DatabaseManager;
use App\Framework\Logging\LogHandler;
use App\Framework\Logging\LogLevel;
use App\Framework\Logging\LogRecord;
@@ -14,7 +15,8 @@ final readonly class QueuedLogHandler implements LogHandler
public function __construct(
private Queue $queue,
#private LogLevel $minLevel = LogLevel::INFO,
){}
) {
}
public function isHandling(LogRecord $record): bool
{

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Framework\Logging\Handlers;
@@ -18,7 +19,8 @@ final class SyslogHandler implements LogHandler
private readonly string $ident = 'php-app',
private readonly int $facility = LOG_USER,
private readonly LogLevel $minLevel = LogLevel::DEBUG
) {}
) {
}
public function isHandling(LogRecord $record): bool
{
@@ -37,7 +39,7 @@ final class SyslogHandler implements LogHandler
private function openSyslog(): void
{
if (!$this->isOpen) {
if (! $this->isOpen) {
openlog($this->ident, LOG_PID | LOG_PERROR, $this->facility);
$this->isOpen = true;
}
@@ -62,7 +64,7 @@ final class SyslogHandler implements LogHandler
// Context-Daten falls vorhanden
$context = $record->getContext();
if (!empty($context)) {
if (! empty($context)) {
$parts[] = 'Context: ' . json_encode($context, JSON_UNESCAPED_SLASHES);
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Framework\Logging\Handlers;
@@ -12,7 +13,8 @@ final class WebHandler implements LogHandler
public function __construct(
private readonly LogLevel $minLevel = LogLevel::DEBUG,
private readonly bool $debugOnly = true
) {}
) {
}
public function isHandling(LogRecord $record): bool
{
@@ -22,7 +24,7 @@ final class WebHandler implements LogHandler
}
// Debug-Modus-Check
if ($this->debugOnly && !filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN)) {
if ($this->debugOnly && ! filter_var(getenv('APP_DEBUG'), FILTER_VALIDATE_BOOLEAN)) {
return false;
}
@@ -55,12 +57,11 @@ final class WebHandler implements LogHandler
// Context-Daten falls vorhanden
$context = $record->getContext();
if (!empty($context)) {
if (! empty($context)) {
$logLine .= ' | Context: ' . json_encode($context, JSON_UNESCAPED_SLASHES);
}
// In error_log schreiben
error_log($logLine);
}
}