BaseLoop different logger

This commit is contained in:
Juan Pablo Vial
2025-05-16 12:54:52 -04:00
parent 8ca68bf7e8
commit f47f86dd2b
4 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,8 @@
<?php
use Psr\Container\ContainerInterface;
return [
DateTimeZone::class => function (ContainerInterface $container) {
return new DateTimeZone($container->get('TZ') ?? 'America/Santiago');
},
];

View File

@ -11,5 +11,11 @@ return [
$container->get(Psr\Log\LoggerInterface::class),
$container->get('commands')
);
},
Incoviba\Command\BaseLoop::class => function(ContainerInterface $container) {
return new Incoviba\Command\BaseLoop(
$container->get('LoopLogger'),
$container->get(Incoviba\Service\Schedule::class)
);
}
];

View File

@ -61,6 +61,23 @@ return [
$container->get(Monolog\Processor\IntrospectionProcessor::class),
$container->get(Monolog\Processor\MemoryUsageProcessor::class),
$container->get(Monolog\Processor\MemoryPeakUsageProcessor::class)
], new DateTimeZone($container->get('TZ')));
], $container->get(DateTimeZone::class));
},
'LoopLogger' => function(ContainerInterface $container) {
return new Monolog\Logger('loop', [
new Monolog\Handler\FilterHandler(
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
? new Monolog\Handler\StreamHandler('/logs/loop.log')
: new Monolog\Handler\RotatingFileHandler('/logs/loop.log', 10),
Monolog\Level::Notice
),
new Monolog\Handler\FilterHandler(
($container->has('ENVIRONMENT') and $container->get('ENVIRONMENT') === 'development')
? new Monolog\Handler\StreamHandler('/logs/loop-debug.log')
: new Monolog\Handler\RotatingFileHandler('/logs/loop-debug.log', 10),
Monolog\Level::Debug,
Monolog\Level::Debug
)
], [], $container->get(DateTimeZone::class));
}
];

View File

@ -44,10 +44,6 @@ class BaseLoop extends Console\Command\Command
}
$nextMinute = new DateTimeImmutable($start->format('Y-m-d H:i:00'));
$nextMinute = $nextMinute->add(new \DateInterval('PT1M'));
$this->logger->debug('Wait', [
'start' => $start->format('Y-m-d H:i:s.u'),
'nextMinute' => $nextMinute->format('Y-m-d H:i:s.u'),
]);
$diff = $nextMinute->getTimestamp() - $start->getTimestamp();
if ($diff > 0) {
$this->logger->debug("Waiting {$diff} seconds...");
@ -66,6 +62,7 @@ class BaseLoop extends Console\Command\Command
'command' => $commandName
]);
try {
$this->logger->notice("Running commnand: {$commandName}");
return $this->getApplication()->doRun($cmd, $output);
} catch (Throwable $exception) {
$this->logger->warning($exception);