Skip to content
Snippets Groups Projects
Select Git revision
  • 0fae43bc716b418a7c975734c1dda39dcfb5178c
  • main default
  • detached3
  • detached2
  • modernisation-gestion-donnees
  • detached
  • 1.5.0
  • 1.4.3
  • 1.4.2
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.2
  • 1.1.1
  • 1.1.0
  • 1.0.6
  • 1.0.5
  • 1.0.4
  • 1.0.3
  • 1.0.2
  • 1.0.1
  • 1.0.0
  • 0.9.10
  • 0.9.9
  • 0.9.8
26 results

LoggerAwareTrait.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    LoggerAwareTrait.php 1.40 KiB
    <?php
    
    namespace Unicaen\BddAdmin\Logger;
    
    use Symfony\Component\Console\Style\SymfonyStyle;
    
    trait LoggerAwareTrait
    {
    
        protected ?LoggerInterface $logger = null;
    
    
    
        /**
         * @return LoggerInterface|null
         */
        public function getLogger(): ?LoggerInterface
        {
            return $this->logger;
        }
    
    
    
        /**
         * @param LoggerInterface|null $logger
         *
         * @return self
         */
        public function setLogger(null|LoggerInterface|SymfonyStyle $logger): self
        {
            if ($logger instanceof SymfonyStyle){
                $logger = new SymfonyStyleLogger($logger);
            }
            $this->logger = $logger;
    
            return $this;
        }
    
    
    
        public function logTitle(string $title): void
        {
            if ($this->logger) $this->logger->title($title);
        }
    
    
        public function logSuccess(string $message): void
        {
            if ($this->logger) $this->logger->success($message);
        }
    
    
        public function logError(string|\Throwable $e): void
        {
            if ($this->logger) $this->logger->error($e);
        }
    
    
    
        public function logBegin(string $title): void
        {
            if ($this->logger) $this->logger->begin($title);
        }
    
    
    
        public function logEnd(?string $msg = null): void
        {
            if ($this->logger) $this->logger->end($msg);
        }
    
    
    
        public function logMsg(string $message, bool $rewrite = false): void
        {
            if ($this->logger) $this->logger->msg($message, $rewrite);
        }
    }