Closed Elfangor93 closed 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?
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.
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
I have tested this PR ✅ successfully. Thank you very much.
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 inJoomla\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
How to test this PR
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');
Visit the site with the following URL in your browser:
http://<Your-Domain>/administrator/index.php?option=com_joomgallery&view=faulties
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