Log all events that happen during an update

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2016-11-24 16:33:05 +01:00
parent cbf943301f
commit 3620d81184
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
1 changed files with 131 additions and 0 deletions

View File

@ -102,6 +102,7 @@ class Updater extends BasicEmitter {
*/
public function upgrade() {
$this->emitRepairEvents();
$this->logAllEvents();
$logLevel = $this->config->getSystemValue('loglevel', Util::WARN);
$this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
@ -477,5 +478,135 @@ class Updater extends BasicEmitter {
});
}
private function logAllEvents() {
$log = $this->log;
$dispatcher = \OC::$server->getEventDispatcher();
$dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($log) {
if (!$event instanceof GenericEvent) {
return;
}
$log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
});
$dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($log) {
if (!$event instanceof GenericEvent) {
return;
}
$log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
});
$repairListener = function($event) use ($log) {
if (!$event instanceof GenericEvent) {
return;
}
switch ($event->getSubject()) {
case '\OC\Repair::startProgress':
$log->info('\OC\Repair::startProgress: Starting ... ' . $event->getArgument(1) . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
break;
case '\OC\Repair::advance':
$desc = $event->getArgument(1);
if (empty($desc)) {
$desc = '';
}
$log->info('\OC\Repair::advance: ' . $desc . ' (' . $event->getArgument(0) . ')', ['app' => 'updater']);
break;
case '\OC\Repair::finishProgress':
$log->info('\OC\Repair::finishProgress', ['app' => 'updater']);
break;
case '\OC\Repair::step':
$log->info('\OC\Repair::step: Repair step: ' . $event->getArgument(0), ['app' => 'updater']);
break;
case '\OC\Repair::info':
$log->info('\OC\Repair::info: Repair info: ' . $event->getArgument(0), ['app' => 'updater']);
break;
case '\OC\Repair::warning':
$log->warning('\OC\Repair::warning: Repair warning: ' . $event->getArgument(0), ['app' => 'updater']);
break;
case '\OC\Repair::error':
$log->error('\OC\Repair::error: Repair error: ' . $event->getArgument(0), ['app' => 'updater']);
break;
}
};
$dispatcher->addListener('\OC\Repair::startProgress', $repairListener);
$dispatcher->addListener('\OC\Repair::advance', $repairListener);
$dispatcher->addListener('\OC\Repair::finishProgress', $repairListener);
$dispatcher->addListener('\OC\Repair::step', $repairListener);
$dispatcher->addListener('\OC\Repair::info', $repairListener);
$dispatcher->addListener('\OC\Repair::warning', $repairListener);
$dispatcher->addListener('\OC\Repair::error', $repairListener);
$this->listen('\OC\Updater', 'maintenanceEnabled', function () use($log) {
$log->info('\OC\Updater::maintenanceEnabled: Turned on maintenance mode', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'maintenanceDisabled', function () use($log) {
$log->info('\OC\Updater::maintenanceDisabled: Turned off maintenance mode', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'maintenanceActive', function () use($log) {
$log->info('\OC\Updater::maintenanceActive: Maintenance mode is kept active', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'updateEnd', function ($success) use($log) {
if ($success) {
$log->info('\OC\Updater::updateEnd: Update successful', ['app' => 'updater']);
} else {
$log->error('\OC\Updater::updateEnd: Update failed', ['app' => 'updater']);
}
});
$this->listen('\OC\Updater', 'dbUpgradeBefore', function () use($log) {
$log->info('\OC\Updater::dbUpgradeBefore: Updating database schema', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'dbUpgrade', function () use($log) {
$log->info('\OC\Updater::dbUpgrade: Updated database', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($log) {
$log->info('\OC\Updater::dbSimulateUpgradeBefore: Checking whether the database schema can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($log) {
$log->info('\OC\Updater::dbSimulateUpgrade: Checked database schema update', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($log) {
$log->info('\OC\Updater::incompatibleAppDisabled: Disabled incompatible app: ' . $app, ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use ($log) {
$log->info('\OC\Updater::thirdPartyAppDisabled: Disabled 3rd-party app: ' . $app, ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($log) {
$log->info('\OC\Updater::upgradeAppStoreApp: Update 3rd-party app: ' . $app, ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($log) {
$log->info('\OC\Updater::appUpgradeCheckBefore: Checking updates of apps', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($log) {
$log->info('\OC\Updater::appSimulateUpdate: Checking whether the database schema for <' . $app . '> can be updated (this can take a long time depending on the database size)', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'appUpgradeCheck', function () use ($log) {
$log->info('\OC\Updater::appUpgradeCheck: Checked database schema update for apps', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'appUpgradeStarted', function ($app) use ($log) {
$log->info('\OC\Updater::appUpgradeStarted: Updating <' . $app . '> ...', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($log) {
$log->info('\OC\Updater::appUpgrade: Updated <' . $app . '> to ' . $version, ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'failure', function ($message) use($log) {
$log->error('\OC\Updater::failure: ' . $message, ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'setDebugLogLevel', function () use($log) {
$log->info('\OC\Updater::setDebugLogLevel: Set log level to debug', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($log) {
$log->info('\OC\Updater::resetLogLevel: Reset log level to ' . $logLevelName . '(' . $logLevel . ')', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($log) {
$log->info('\OC\Updater::startCheckCodeIntegrity: Starting code integrity check...', ['app' => 'updater']);
});
$this->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($log) {
$log->info('\OC\Updater::finishedCheckCodeIntegrity: Finished code integrity check', ['app' => 'updater']);
});
}
}