magento2: exception.log missing

Preconditions and environment

  • Magento version 2.4.5
  • PHP 8.1 (FPM)
  • Apache2.4
  • Ubuntu 20.04

This Magento install has

Steps to reproduce

Trigger an exception/error (for example reCAPTCHA error detailed in #34975), or make generated/ directory read-only to trigger a read-only error.

Expected result

I expect to see an error and trace in var/log/exception.log

Actual result

No exception.log exists. Errors do seem to appear in system.log, but I don’t know if they are everything that should be in exception.log.

Additional information

This instance of Magento has been updated since 2.0 to 2.2 and 2.4. In the past exception.log was always present with errors/exceptions.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 53 (8 by maintainers)

Most upvoted comments

@engcom-November - Ah! Haha that’s a really funny april fools joke!!

Oh wait, it’s the middle of October, it’s not April 1st.

** THIS IS A BUG ** var/log/exception.log is a well established log for critical errors. This is not about custom code/modules, user logging. This is fundamental, built in logging from standard usage of Magento. References to it are littered throughout the official Magento documentation. Have a look.
** THIS IS A BUG **

eg. https://devdocs.magento.com/cloud/project/log-locations.html Exception log: var/log/exception.log

https://experienceleague.adobe.com/docs/commerce-operations/configuration-guide/cli/configure-cron-jobs.html Jobs with an ERROR status are always logged as CRITICAL in <install_directory>/var/log/exception.log.

etc etc

@MeetKamal

We have verified this issue in our local environment and found work around(temporary) solution for it.

File path where need to replace core code: vendor/magento/framework/Logger/Handler/System.php

Please replace below code:

public function write(array $record): void
    {
        if (isset($record['context']['exception'])) {
            $this->exceptionHandler->handle($record);

            return;
        }
        $record['formatted'] = $this->getFormatter()->format($record);

        parent::write($record);
    }

With :

public function write(array $record): void
    {
        	
        if (isset($record['context']['exception']) || $record['level'] == Logger::CRITICAL) {
            $this->exceptionHandler->handle($record);

            return;
        }
        $record['formatted'] = $this->getFormatter()->format($record);

        parent::write($record);
    }

100% agree with @siliconalchemy

Having all kind of log severities in the same file (system.log) really makes it difficult to use and defeats the purpose of log severity in the first place. We have to employ various workarounds (like parsing rules) to filter out “noise” lines in order to have a realistic overview of actual issues.

Furthermore, exception.log is not populated not only by custom/third party code, but also by Magento core code itself.

At least we could expect from core team to list this so-called “feature” in their release notes, as a backwards incompatible change. But ideally, this should be fixed to work as in the previous versions.

I agree, this is by far not a feature. Please take your time and fix this. It has been month and nothing happened.

Verified the issue on fresh instance of 2.4.5 Project-community-edition and the issue is reproducible. exception.log file is missing in var/log folder. No errors are written into exception.log. Only all errors are written into system.log file. Note: There is no issue when the Magento is upgraded to 2.4.5 from 2.4.3 Project-community-edition. exception.log file is present in this case and all the errors/exceptions are getting written into exception.log file as expected. Hence confirming this issue.

😆 In that thought process they need to leave open every ticket for forever and never close one, because there will always be a user that can’t update to some version.

Anyway, if a fix has been published, they close the issue, it’s as simple as that.

My patch isn’t official, that’s very true, if you don’t trust it, then please make your own patch, the commits with fixes were already mentioned earlier: https://github.com/magento/magento2/issues/36054#issuecomment-1327131002

There is no other way you’ll get what you want, so please get into the habit of creating your own patches for bugs you need to have fixed, you’re bound to run into another bug in the future that has been fixed in some commit, so it’s a good skill to have to turn those commits into patches.

Hello @siliconalchemy @adriansanta @kamephis @jurvi @briangmoore77, We have discussed this issue again internally and after further analysis came across the below commit: https://github.com/magento/magento2/commit/8e6aedc8130be01669b04f99c19ab3f48e4c0691 We are confirming this issue and further analysis is in progress. Thank you.

There isn’t as far as I know, at least I can’t find one when searching using their quality patches tool. As to why not, no idea, but probably Adobe didn’t feel like it was important enough to create one…

So either take one of the solutions here from the thread, or make one yourself if you don’t trust it (which is what I would recommend), or upgrade to 2.4.6-p1, or if you really want an official patch, create an issue or pull request here: https://github.com/magento/quality-patches (but knowing Adobe, it might take some weeks/months/years until you’ll get one)

2.4.6 is out and includes this patch/fix.

Just a quick note to say this worked for me: https://magento.stackexchange.com/questions/361276/exception-log-is-missing-in-magento2-4-4

--- a/vendor/magento/framework/Logger/Handler/System.php
+++ b/vendor/magento/framework/Logger/Handler/System.php
@@ -55,7 +55,7 @@
      */
     public function write(array $record): void
     {
-        if (isset($record['context']['exception'])) {
+        if (isset($record['context']['exception']) || $record['level'] == Logger::CRITICAL) {
             $this->exceptionHandler->handle($record);

             return;

Or use my earlier referenced patch that is based on the official Adobe fix? (A lot time of could have been won if you just had read all the comments in this thread 😉)

@Eddcapone Here i am attach the patch file, you can use this patch untill the your system is not being updated to the 2.4.6 exception_log.zip

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket ACP2E-1287 by the internal team Related commits: https://github.com/magento/magento2/search?q=ACP2E-1287&type=commits

Based on the Jira ticket, the target version is 2.4.6.

Thanks

Still no exception.log in M2.4.5-p1

Is this going backwards? I figured this would be fixed by now.

Hi @Shaikh-Samir - Thank you for the Work around, Have tested and it seems working 😃

@sdzhepa: can we have somebody to verify this? This indeed sounds like a P0 or P1 prio if it’s true. Thanks!

I can not confirm that this is true on Magento 2.4.3-p3 on production shops of ours, it works as expected over there. We haven’t tried 2.4.4 or 2.4.5 yet in production, so I can’t speak about those versions yet.

Any updates on this? Nobody seems to care about such a severe issue.