123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace OC\Console;
- use OCP\IConfig;
- use Symfony\Component\Console\Formatter\OutputFormatterInterface;
- use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
- class TimestampFormatter implements OutputFormatterInterface {
-
- protected $config;
-
- protected $formatter;
-
- public function __construct(?IConfig $config, OutputFormatterInterface $formatter) {
- $this->config = $config;
- $this->formatter = $formatter;
- }
-
- public function setDecorated(bool $decorated) {
- $this->formatter->setDecorated($decorated);
- }
-
- public function isDecorated(): bool {
- return $this->formatter->isDecorated();
- }
-
- public function setStyle(string $name, OutputFormatterStyleInterface $style) {
- $this->formatter->setStyle($name, $style);
- }
-
- public function hasStyle(string $name): bool {
- return $this->formatter->hasStyle($name);
- }
-
- public function getStyle(string $name): OutputFormatterStyleInterface {
- return $this->formatter->getStyle($name);
- }
-
- public function format(?string $message): ?string {
- if (!$this->formatter->isDecorated()) {
-
- return $this->formatter->format($message);
- }
- if ($this->config instanceof IConfig) {
- $timeZone = $this->config->getSystemValue('logtimezone', 'UTC');
- $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
- $time = new \DateTime('now', $timeZone);
- $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTimeInterface::ATOM));
- } else {
- $time = new \DateTime('now');
- $timestampInfo = $time->format(\DateTimeInterface::ATOM);
- }
- return $timestampInfo . ' ' . $this->formatter->format($message);
- }
- }
|