1212use Nextcloud \LogNormalizer \Normalizer ;
1313use OC \AppFramework \Bootstrap \Coordinator ;
1414use OC \Log \ExceptionSerializer ;
15+ use OCP \App \IAppManager ;
1516use OCP \EventDispatcher \IEventDispatcher ;
1617use OCP \ILogger ;
1718use 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 ' ;
0 commit comments