Skip to content

Commit ddf8c95

Browse files
committed
feat: log app version
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent f608cf4 commit ddf8c95

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/private/Log.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Nextcloud\LogNormalizer\Normalizer;
1313
use OC\AppFramework\Bootstrap\Coordinator;
1414
use OC\Log\ExceptionSerializer;
15+
use OCP\App\IAppManager;
1516
use OCP\EventDispatcher\IEventDispatcher;
1617
use OCP\ILogger;
1718
use OCP\IRequest;
@@ -44,6 +45,7 @@ public function __construct(
4445
private SystemConfig $config,
4546
private Normalizer $normalizer = new Normalizer(),
4647
private ?IRegistry $crashReporters = null,
48+
private ?IAppManager $appManager = null,
4749
) {
4850
}
4951

@@ -142,7 +144,6 @@ public function debug(string $message, array $context = []): void {
142144
$this->log(ILogger::DEBUG, $message, $context);
143145
}
144146

145-
146147
/**
147148
* Logs with an arbitrary level.
148149
*
@@ -158,6 +159,9 @@ public function log(int $level, string $message, array $context = []): void {
158159
return; // no crash reporter, no listeners, we can stop for lower log level
159160
}
160161

162+
if ($this->appManager && isset($context['app']) && $version = $this->appManager->getAppVersion($context['app'])) {
163+
$context['app_version'] = $version;
164+
}
161165
array_walk($context, [$this->normalizer, 'format']);
162166

163167
$app = $context['app'] ?? 'no app in context';

lib/private/Server.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,9 @@ public function __construct($webRoot, \OC\Config $config) {
695695
$factory = new LogFactory($c, $this->get(SystemConfig::class));
696696
$logger = $factory->get($logType);
697697
$registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
698+
$appManager = $c->get(AppManager::class);
698699

699-
return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry);
700+
return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry, appManager: $appManager);
700701
});
701702
// PSR-3 logger
702703
$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);

0 commit comments

Comments
 (0)