Skip to content

Instantly share code, notes, and snippets.

@axi
Created June 21, 2024 17:13
Show Gist options
  • Select an option

  • Save axi/779b9892aaeab204699c4f01946bf35b to your computer and use it in GitHub Desktop.

Select an option

Save axi/779b9892aaeab204699c4f01946bf35b to your computer and use it in GitHub Desktop.
PsrLoggerWrapper for WC_Logger
<?php
use Psr\Log\LoggerInterface;
class PsrLoggerWrapper implements LoggerInterface
{
private WC_Logger_Interface $logger;
public function __construct(WC_Logger_Interface $logger = null)
{
$this->logger = $logger ?? wc_get_logger();
}
public function error(string|\Stringable $message, array $context = []): void
{
$this->logger->error($message, $context);
}
public function emergency(string|\Stringable $message, array $context = []): void
{
$this->logger->emergency($message, $context);
}
public function alert(string|\Stringable $message, array $context = []): void
{
$this->logger->alert($message, $context);
}
public function critical(string|\Stringable $message, array $context = []): void
{
$this->logger->critical($message, $context);
}
public function warning(string|\Stringable $message, array $context = []): void
{
$this->logger->warning($message, $context);
}
public function notice(string|\Stringable $message, array $context = []): void
{
$this->logger->notice($message, $context);
}
public function info(string|\Stringable $message, array $context = []): void
{
$this->logger->info($message, $context);
}
public function debug(string|\Stringable $message, array $context = []): void
{
$this->logger->debug($message, $context);
}
/**
* @param string $level One of the following (WC_Log_Levels|Psr\Log\LogLevel constant):
* 'emergency': System is unusable.
* 'alert': Action must be taken immediately.
* 'critical': Critical conditions.
* 'error': Error conditions.
* 'warning': Warning conditions.
* 'notice': Normal but significant condition.
* 'info': Informational messages.
* 'debug': Debug-level messages.
* @param string|\Stringable $message
* @param array $context
* @return void
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
$this->logger->log($level, $message, $context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment