Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WebProfilerBundle] Display again the number of occurrences of log messages #45198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

javiereguiluz
Copy link
Member

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #45183
License MIT
Doc PR -

It looks like this:

log-occurrences

@javiereguiluz
Copy link
Member Author

As @SVillette pointed out to me via Symfony Slack, the current profiler before this PR already displayed the "log counter":

image (1)

So, the real problem might be that the log counter of LoggerProfiler doesn't work.

@SVillette also mentioned that doing the following change in LoggerDataCollector::getProcessedLogs() solve the problem for them:

$logs[] = [
  ...
  'errorCounter' => isset($rawLogData['errorCounter']) ? $rawLogData['errorCounter']->getValue() : 1,
  'errorCount' => $rawLog['errorCount'] ?? 1,  // The line I added to make it worked
  ...
];

I need help to know how to move forward with this. Thanks!

@nicolas-grekas
Copy link
Member

This could qualify as a bug fix IMHO.
About the count, "15" looks like it's correct to me.

@SVillette
Copy link
Contributor

Hi @nicolas-grekas, I will clarify a little about what has been done.

The issue is not about global count ("15") but the count per log ("5 times").
Symfony 5.4 added a new method LoggerDataCollector::getProcessedLogs() that introduced errorCounter when processing a single log, but the template (Collector/logger.html.twig at line 241) only display log.errorCount which is never defined.

public function getProcessedLogs()
{
...
    $logs[] = [
...
        'errorCounter' => isset($rawLogData['errorCounter']) ? $rawLogData['errorCounter']->getValue() : 1,
    ];
...
    return $this->processedLogs = $logs;
}
{% macro render_log_message(category, log_index, log) %}
...
    {% if log.errorCount is defined and log.errorCount > 1 %}
         <span class="log-num-occurrences">{{ log.errorCount }} times</span>
    {% endif %}
...
{% endmacro %}

" the current profiler before this PR already displayed the "log counter""

To reformulate what @javiereguiluz said, the template was already displaying the right information but the LoggerDataCollector does not pass the errorCount when getting the processed logs.

From what I debugged $rawLogData['errorCounter'] is not defined and so errorCounter value is always 1. I cannot affirm this is always the case.

So that's why I just modified errorCounter by errorCount in the LoggerDataCollector. In addition, $rawLogData does not contain neither errorCounter nor errorCount so I just used $rawLog['errorCount'].

$logs[] = [
    'errorCount' => $rawLog['errorCount'] ?? 1,
];

I hope my explanation are clear, I can open a PR if you consider it is a bug fix.

@SVillette
Copy link
Contributor

Finally, I want to add that a global search on errorCounter only display LoggerDataCollector::getProcessedLogs() and LoggerDataCollector::testCollectFromDeprecationsLog(). I don't see any other usages.

@javiereguiluz
Copy link
Member Author

Closing in favor of a better fix in #45302. Thanks!

fabpot added a commit that referenced this pull request Feb 4, 2022
…ot displayed in WebProfilerBundle (SVillette)

This PR was merged into the 5.4 branch.

Discussion
----------

[HttpKernel][WebProfilerBundle] Fixed error count by log not displayed in WebProfilerBundle

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #45183
| License       | MIT
| Doc PR        | -

This PR is the following of #45198. Refer to this PR for details.

![image](https://user-images.githubusercontent.com/17042730/152384024-64ffecb3-d895-450b-a994-fe3d54582680.png)

Commits
-------

5e1a2cb [HttpKernel] Fixed error count by log not displayed in WebProfilerBundle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Profiler] Logs > Deprecations tab doesn't show how often a single deprecation is triggered
4 participants