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