Cockpit-HQ / Cockpit

Cockpit Core - Content Platform
https://getcockpit.com
Other
378 stars 45 forks source link

Logs cannot be loaded without MongoDB #85

Open Franiac opened 1 year ago

Franiac commented 1 year ago

I am currently trying out Cockpit Core. I realized that I cannot display any logs in Settings -> Logs. The loading indicator just does not stop spinning when the route /system/logs gets called.

Checked the JavaScript console and:

MongoLite\\Database::callCriteriaFunction(): Argument #2 ($document) must be of type array, null given

Well... I do not use MongoDB and therefor it is not configured in config.php.

In Logs.php I found this:

public function load() {

        $this->helper('session')->close();

        $options = array_merge([
            'sort' => ['timestamp' => -1]
        ],$this->param('options', []));

        $items = $this->app->dataStorage->find('system/log', $options)->toArray();
        $count = $this->app->dataStorage->count('system/log', $options['filter'] ?? []);
        $pages = isset($options['limit']) ? ceil($count / $options['limit']) : 1;
        $page  = 1;

        if ($pages > 1 && isset($options['skip'])) {
            $page = ceil($options['skip'] / $options['limit']) + 1;
        }

        return compact('items', 'count', 'pages', 'page');
    }

And $this->app->dataStorage is initialized in bootstrap.php with

$app->service('dataStorage', function() use($config) {
        $client = new MongoHybrid\Client($config['database']['server'], $config['database']['options'], $config['database']['driverOptions']);
        return $client;
   });

Conclusion:

Logs don't work without a Mongo Database.

I have not digged any deeper but it seems like there is a small concept error. Should logs not also be able to get stored in SQLite if MongoDB is not used? Or am I missing something here?

aheinze commented 1 year ago

I'm running multiple cockpit instances using SQLite. Never experienced such issue. Can you try to delete the log table in /storage/data/system.sqlite?

Franiac commented 1 year ago

Got some news:

Uploaded Cockpit to my webspace (strato.de) and tested it there and it workes fine.

The issue occures on a local XAMPP stack. We could compare phpinfo() in order to get some ideas as to why this happens. My first wild shot would be that my hosting provider has PHP MongoDB extensions enabled by default whereas XAMPP does not (not confirmed so far).

Do you even want to investigate this issue?

I am a software dev myself and I would understand a simple "XAMPP is not my problem, so don't care" 😄

But it is a widespread local development stack for PHP so in my opinion it has some weight to it.

aheinze commented 1 year ago

I can't test all possible dev stacks but feel invited to make it work on XAMPP 😉

raffaelj commented 1 year ago

@aheinze Finally I was able to reproduce an event with an empty error log:

  1. Comment out use Symfony\Component\Console\Input\InputArgument; in https://github.com/Cockpit-HQ/Cockpit/blob/develop/modules/System/Command/Spaces/Create.php#L7
  2. Run ./tower
  3. See empty error log in system.sqlite

I discovered it while writing a new cli command (to create a user) with ->addOption and I forgot to use Symfony\Component\Console\Input\InputOption;.

I fiddled a bit with commenting out error handling, unsetting $error['trace'] and piping output to error.txt. It looks like the exceptions are caught, but the SQLite database stops writing without throwing a new exception.

So I guess, a trace of >95k characters (error.txt is ~95kb), which contains the whole Lime\App is too big and SQLite silently fails.