JoomGalleryfriends / JG4-dev

Development repository for JoomGallery v4.x
GNU General Public License v3.0
10 stars 6 forks source link

Simplifying usage of addLog() #242

Closed Elfangor93 closed 3 weeks ago

Elfangor93 commented 3 weeks ago

Before this PR $this->component->addLog(string $txt, $priority = 8, string $name = null) the second argument needed to be a integer with a proper value for the type of message based on the constants defined in Joomla\CMS\Log\Log. With this PR it is now possible to choose the type of message by providing a string with the proper name of the message type.

Before this PR $this->component->addLog('My error message', 8, 'jerror') which is the same as $this->component->addLog('My error message', Log::ERROR, 'jerror')

After this PR $this->component->addLog('My error message', 'error', 'jerror')

Where the old way is still possible.

This fixes the issue reported in PR #239

0 Class “Joomgallery\Component\Joomgallery\Administrator\Model\Log” not found 1 () JROOT\administrator\components\com_joomgallery\src\Model\CategoryModel.php:297 2 Joomgallery\Component\Joomgallery\Administrator\Model\CategoryModel->delete() JROOT\libraries\src\MVC\Controller\AdminController.php:143 3 Joomla\CMS\MVC\Controller\AdminController->delete() JROOT\libraries\src\MVC\Controller\BaseController.php:693

How to test this PR

  1. Open the file /com_joomgallery/administrator/src/View/Faulties and add the following code after line 49 (in front of the return statement): $this->component->addLog('My error message for testing.', 'warning', 'jerror');

  2. Visit the site with the following URL in your browser: http://<Your-Domain>/administrator/index.php?option=com_joomgallery&view=faulties

  3. Check that the message was added to the jerror log file /administrator/logs/com_joomgallery.jerror.log.php

Repeat the test by changing the second argument in addLog() in step 1. Possible values for the second argument are: all, emergency, alert, critical, error, warning, notice, info, debug

MrMusic commented 3 weeks ago

I have done some tests with the second parameter: With numerical values (1, 2, 4,...) it works fine. With strings ('error', 'warning', 'notice'...) it works fine. What does not work is using the Joomla constants (Log::alert, Log::ERROR, ...). Would it be useful if you could also use the Joomla constants?

Elfangor93 commented 3 weeks ago

What does not work is using the Joomla constants (Log::alert, Log::ERROR, ...).

These are not Joomla constants. They are constants defined in the Log class. In order to use that you need to load the Log class into your current scope by doing use Joomla\CMS\Log\Log. As soon as you loaded the constants into your scope you can use them.

MrMusic commented 3 weeks ago

In order to use that you need to load the Log class into your current scope by doing use Joomla\CMS\Log\Log.

That is of course, I have already added that.

The problem was actually that I didn't pay attention to upper/lower case when testing. Log::WARNING -> ok Log::warning -> error

MrMusic commented 3 weeks ago

I have tested this PR ✅ successfully. Thank you very much.