As we all know the logging of deprecated function works always, even when the debug is disabled, that cause a performance issue.
Especially on 4.0 version where is a tons of deprecated methods.
Log in to backend.
Disable debug.
Then edit administrator/index.php
,
change:
require_once dirname(__FILE__) . '/includes/app.php';
to:
$starttime = microtime(1);
require_once dirname(__FILE__) . '/includes/app.php';
$endtime = microtime(1);
var_dump($endtime - $starttime);
Visit the Home Dahsboard, and Artciles, and other pages, and note the time that displayed at end of every page.
Then edit libraries/src/Log/Log.php
, at beginning on function add()
add early return;
(mimic disabled logs)
joomla-cms/libraries/src/Log/Log.php
Lines 161 to 164 in 25f8d40
public static function add($entry, $priority = self::INFO, $category = '', $date = null, array $context = array())
{
return;
// Automatically instantiate the singleton object if not already done.
...
...
Then visit same pages again, and note the time.
Time should be around the same
Time dropped much (rendering become faster), in my test around 30-50% depend from page. On real hosting it can be much worse.
I would suggest to wrap all such logs in to if (DEBUG)
, or if ($app->get('log_deprecated'))
(when #30317 will be merged)
Or maybe some helper method that will be as proxy-wrapper for deprecated log.
Labels |
Added:
?
|
confused as I only get the deprecated api logging when I specifically enable it
The issue is when you disable the logging it does not disable logging itself, you just not see it ;)
Example look:
joomla-cms/libraries/src/HTML/HTMLHelper.php
Lines 208 to 221 in 9cc6cb1
It always call Log:add(), no mater if you have enabled logging or not.
ah - I see what you mean now
That's the reason why we have to find ways to log deprecation calls only once like the $app->isAdmin() function... but that's not so easy because if you call it only once then you see only one stacktrace and have to fix this then with the next call you see the next stackstrace and have to fix this and so on....
And I think that's the reason why isAdmin() and isSite() doesn't have Log entries and only the deprecation comment. To get all depredations you can use https://api.joomla.org/cms-3/deprecated.html
On my own preference,
I would like to have a performant site were the Log function is not called everytime regardless of my Logging settings.
A possible solution could be a ontime check on depricated functions when enabling that plugin and showing a warning modal that this plugin uses <depricated function>
and the developer should not use this function.
Yes, that would mean, the average user would get that message too, when he enable that plugin / extension, but only once.
@HLeithner @wilsonge what do you think about some "proxy" helper?
kind of like this:
class LogHelper
{
public static function deprecatedMethod($method, $endVersion, $message = '')
{
if (!Factory::getAplication()->get('log_deprecated'))
{
return;
}
try
{
Log::add(
sprintf('% is deprecated, and will be removed in %s.%s', $method, $endVersion, ($message ? ' ' . $message : '')),
Log::WARNING,
'deprecated'
);
}
catch (\RuntimeException $exception)
{
// Silents
}
}
}
Then just call:
LogHelper::deprecatedMethod(__METHOD__, '5.0');
a static cache for getApplication()->get('log_deprecated') could make sense
I also thought, or some constant
Actually we shouldn't introduce any global or static constants but since this is a Application wide setting I think something like
static $logDeprecated = null;
if (!is_null($logDeprecated)) {
$logDeprecated = Factory::getAplication()->get('log_deprecated');
}
should fit our needs.
but maybe a static public function could help extension developer to be more flexible...
yea, a bit hacky :)
I think use of helper will add more consistency with "deprecation".
I will prepare PR, when will get some time.
the only thin I will prevent is to rewrite all deprecation entries... I would not introduce a new class I would use the Log
class and add a LogDeprecated
function if not directly in the log
function
why just not do something like this
// We only want to handle user deprecation messages, these will be triggered in code
if ($errorNumber === E_USER_DEPRECATED)
{
// If debug mode is enabled, we want to let PHP continue to handle the error; otherwise, we can bail early
if (\defined('JDEBUG') && JDEBUG)
{
Log::add(
$errorMessage,
Log::WARNING,
'deprecated'
);
return true;
}
}
That's the reason why we have to find ways to log deprecation calls only once
This seems wrong to me. The purpose of a log is to log things. Not to see if it has been logged before. If I load a page that should log something then I would expect to see it in the log. How else would I know there is an issue.
I visit page 1 and it logs "issue with function a"
I visit page 2 and it doesn't log "issue with function a" because there is already a log entry for "issue with function a"
How does that help me? I would think there is nothing wrong with page 2.
@brianteeman you misunderstood, @HLeithner talked about call "per request",
In your example it will log on page 1 and page 2, but only once per page.
However it still has limitation, he wrote it in the same comment ;)
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-10-18 10:00:08 |
Closed_By | ⇒ | Fedik |
/me confused as I only get the deprecated api logging when I specifically enable it