alltube/classes/Factory/LoggerFactory.php

41 lines
978 B
PHP
Raw Normal View History

<?php
2020-10-20 21:29:50 +00:00
namespace Alltube\Factory;
use Consolidation\Log\Logger;
2021-02-06 14:00:26 +00:00
use Consolidation\Log\LoggerManager;
use Consolidation\Log\LogOutputStyler;
use Slim\Container;
use Symfony\Component\Console\Output\ConsoleOutput;
2022-02-03 19:01:56 +00:00
use Symfony\Component\Console\Output\OutputInterface;
/**
* Class LoggerFactory
* @package Alltube
*/
class LoggerFactory
{
/**
* @param Container $container
2021-02-06 14:00:26 +00:00
* @return LoggerManager
*/
2021-02-06 14:00:26 +00:00
public static function create(Container $container): LoggerManager
{
$config = $container->get('config');
if ($config->debug) {
2022-02-03 19:01:56 +00:00
$verbosity = OutputInterface::VERBOSITY_DEBUG;
} else {
2022-02-03 19:01:56 +00:00
$verbosity = OutputInterface::VERBOSITY_NORMAL;
}
2021-02-06 14:00:26 +00:00
$loggerManager = new LoggerManager();
$logger = new Logger(new ConsoleOutput($verbosity));
$logger->setLogOutputStyler(new LogOutputStyler());
2021-02-06 14:00:26 +00:00
$loggerManager->add('default', $logger);
return $loggerManager;
}
}