Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions lib/Support/LoggerInterfaceToOutputAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCA\PreviewGenerator\Support;

use JsonException;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Stringable;
Expand All @@ -21,51 +22,51 @@ public function __construct(
}

public function emergency(string|Stringable $message, array $context = []): void {
$this->writeToOutput('error', $message, $context);
$this->writeToOutput('error', (string)$message, $context);
}

public function alert(string|Stringable $message, array $context = []): void {
$this->writeToOutput('error', $message, $context);
$this->writeToOutput('error', (string)$message, $context);
}

public function critical(string|Stringable $message, array $context = []): void {
$this->writeToOutput('error', $message, $context);
$this->writeToOutput('error', (string)$message, $context);
}

public function error(string|Stringable $message, array $context = []): void {
$this->writeToOutput('error', $message, $context);
$this->writeToOutput('error', (string)$message, $context);
}

public function warning(string|Stringable $message, array $context = []): void {
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_NORMAL) {
return;
}

$this->writeToOutput(null, $message, $context);
$this->writeToOutput(null, (string)$message, $context);
}

public function notice(string|Stringable $message, array $context = []): void {
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) {
return;
}

$this->writeToOutput(null, $message, $context);
$this->writeToOutput(null, (string)$message, $context);
}

public function info(string|Stringable $message, array $context = []): void {
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) {
return;
}

$this->writeToOutput(null, $message, $context);
$this->writeToOutput(null, (string)$message, $context);
}

public function debug(string|Stringable $message, array $context = []): void {
if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_DEBUG) {
return;
}

$this->writeToOutput(null, $message, $context);
$this->writeToOutput(null, (string)$message, $context);
}

public function log($level, $message, array $context = []): void {
Expand All @@ -81,20 +82,18 @@ public function log($level, $message, array $context = []): void {
};
}

private function writeToOutput(
?string $decorator,
string|Stringable $message,
array $context = [],
): void {
$message = (string)$message;
private function writeToOutput(?string $decorator, string $message, array $context = []): void {
if (!empty($context)) {
$message .= ' ' . json_encode($context);
try {
$message .= ' ' . json_encode($context, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
}
}

if ($decorator) {
$this->output->writeln("<$decorator>$message</$decorator>");
} else {
$this->output->writeln($message);
$message = "<$decorator>$message</$decorator>";
}

$this->output->writeln($message);
}
}
Loading