1

I'm trying to make a script to update components and I want to retrieve the logs to check the execution of all the requests related to the update of a component.

In the script I use Joomla methods, external to my script, so I need to activate the debug variable dynamically from the configuration file to log all the queries executed. (I get them with JDatabaseDriver::getLog())

In the case where I activate the debug before the execution of the script, everything goes as planned, I have my logs.

But when I activate it from the script, my logs are empty. The debug variable goes to true (in the conf file), but that seems to have no effect at the script level, I don't get the logs.

Do you have an idea to solve this problem or work around it?

Sorry for my poor English... Thanks in advance and have a nice day!

Edit :

Code use to change debug to true :

$config = JFactory::getConfig();
$config->set('debug', '1');

Method use to get statements logs :

private function getElementLogs() {
        $logs = $this->db->getLog();
        if($this->logs) {
            foreach ($logs as $key => $value) {
                if ($logs[$key] == $this->logs[$key] AND isset($logs[$key])) {
                    unset($logs[$key]);
                }
            }
        }
        $this->logs = $this->db->getLog();
        return $logs;
    }

1 Answer 1

2

If you're using JFactory::getDbo() to get the database instance, it could be that something else calls it before you set the configuration value. So you would need to make sure you set debug configuration as early as possible. Possibly better solution for your case is to use JDatabaseDriver::setDebug() to set the debug value manually on the database instance. Note that queries executed before this value is set will not be collected. That should be OK if you're only interested in specific queries of your script. Another option is to use a separate database instance independent of JFactory.

2
  • JDatabaseDriver::setDebug() works perfectly ! Thanks you very much @Sharky! Seems to havea problem with my account (maybe multi account from mail adress), I can't log with good user and can't close the question :/ Aug 18, 2022 at 14:47
  • joomla.stackexchange.com/help/…. Aug 18, 2022 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.