protected function cleanupOldLogs($logDir)
    {
        if ($this->useLogging === false) {
            // We have no write access. Do nothing.
            return;
        }

        // Cleanup old logfiles to prevent a overflow.
        $logList = glob($logDir . '*.Krexx.html');
        if (empty($logList) === true) {
            return;
        }

        array_multisort(
            array_map(array($this->pool->fileService, 'filetime'), $logList),
            SORT_DESC,
            $logList
        );

        $maxFileCount = (int)$this->pool->config->getSetting(Fallback::SETTING_MAX_FILES);
        $count = 1;
        // Cleanup logfiles.
        foreach ($logList as $file) {
            if ($count > $maxFileCount) {
                $this->pool->fileService->deleteFile($file);
                $this->pool->fileService->deleteFile($file . '.json');
            }

            ++$count;
        }
    }