name : LoggerTrait.php
<?php

namespace Vonage\Logger;

use Psr\Log\LoggerInterface;

trait LoggerTrait
{
    /**
     * @var LoggerInterface
     */
    protected $logger;

    public function getLogger(): ?LoggerInterface
    {
        return $this->logger;
    }

    /**
     * @param string|int $level Level of message that we are logging
     * @param array<mixed> $context Additional information for context
     */
    public function log($level, string $message, array $context = []): void
    {
        $logger = $this->getLogger();
        if ($logger) {
            $logger->log($level, $message, $context);
        }
    }

    public function setLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }
}

© 2025 UnknownSec
A-Z Web Programming | Anyleson - Learning Platform
INR (₹)
India Rupee
$
United States Dollar
A-Z Web Programming

A-Z Web Programming

in Web Development
4.75
(1 Ratings)
Created by Linda Anderson

Share

Share course with your friends

Buy with points