Add plugins version to logs

[MAILPOET-4735]
This commit is contained in:
Pavel Dohnal
2022-11-23 11:34:40 +01:00
committed by Veljko V
parent 02b82c04f3
commit fd1331e602
3 changed files with 18 additions and 2 deletions

View File

@ -82,6 +82,9 @@ class LoggerFactory {
$this->loggerInstances[$name]->pushProcessor(new MemoryUsageProcessor()); $this->loggerInstances[$name]->pushProcessor(new MemoryUsageProcessor());
} }
// Adds the plugin's versions to the log, we always want to see this
$this->loggerInstances[$name]->pushProcessor(new PluginVersionProcessor());
$this->loggerInstances[$name]->pushHandler(new LogHandler( $this->loggerInstances[$name]->pushHandler(new LogHandler(
$this->logRepository, $this->logRepository,
$this->entityManager, $this->entityManager,

View File

@ -0,0 +1,13 @@
<?php declare (strict_types=1);
namespace MailPoet\Logging;
use MailPoet\Config\Env;
class PluginVersionProcessor {
public function __invoke(array $record): array {
$record['extra']['free_plugin_version'] = Env::$version;
$record['extra']['premium_plugin_version'] = defined('MAILPOET_PREMIUM_VERSION') ? MAILPOET_PREMIUM_VERSION : 'premium not installed';
return $record;
}
}

View File

@ -39,13 +39,13 @@ class LoggerFactoryTest extends \MailPoetUnitTest {
public function testItAttachesProcessors() { public function testItAttachesProcessors() {
$logger1 = $this->loggerFactory->getLogger('logger-with-processors', true); $logger1 = $this->loggerFactory->getLogger('logger-with-processors', true);
$processors = $logger1->getProcessors(); $processors = $logger1->getProcessors();
expect($processors)->notEmpty(); expect(count($processors))->greaterThan(1);
} }
public function testItDoesNotAttachProcessors() { public function testItDoesNotAttachProcessors() {
$logger1 = $this->loggerFactory->getLogger('logger-without-processors', false); $logger1 = $this->loggerFactory->getLogger('logger-without-processors', false);
$processors = $logger1->getProcessors(); $processors = $logger1->getProcessors();
expect($processors)->isEmpty(); expect($processors)->count(1);
} }
public function testItAttachesHandler() { public function testItAttachesHandler() {