Skip to content

Commit

Permalink
Add a bit more details to log
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuesken committed Jan 23, 2025
1 parent 36fdfd8 commit 636a822
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Log/WcPsrLoggerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class WcPsrLoggerAdapter extends AbstractLogger
*/
private $loggingLevel;

private string $loggingThreadId = '';

/**
* WcPsrLoggerAdapter constructor.
*
Expand All @@ -61,6 +63,7 @@ public function __construct(
\assert(in_array($loggingLevel, $this->psrWcLoggingLevels, true));
$this->loggingLevel = $loggingLevel;
$this->loggerSource = $loggerSource;
$this->loggingThreadId = uniqid();
}

/**
Expand All @@ -79,6 +82,13 @@ public function log($level, $message, array $context = [])
$wcLevel = $this->psrWcLoggingLevels[$level];
}

if ($context === [true]) {
$context = [];
}
$context['threadId'] = $this->loggingThreadId;
$context['request_vars'] = $_REQUEST;
$context['request_uri'] = $_SERVER['REQUEST_URI'];

if (\WC_Log_Levels::get_level_severity($wcLevel) < \WC_Log_Levels::get_level_severity($this->loggingLevel)) {
$message = sprintf("Unknown log level %s", $wcLevel);
throw new InvalidArgumentException(esc_html($message));
Expand Down

0 comments on commit 636a822

Please sign in to comment.