|
| 1 | +--- |
| 2 | +title: Exception Log Level configuration |
| 3 | +date: 2023-05-25 |
| 4 | +area: core |
| 5 | +tags: [core, devops, observability] |
| 6 | +--- |
| 7 | + |
| 8 | +# Exception Log Level configuration |
| 9 | + |
| 10 | +{% hint style="info" %} |
| 11 | +This document represents an architecture decision record (ADR) and has been mirrored from the ADR section in our Shopware 6 repository. |
| 12 | +You can find the original version [here](https://github.com/shopware/platform/blob/trunk/adr/2023-05-25-exception-log-levels.md) |
| 13 | +{% endhint %} |
| 14 | + |
| 15 | +## Context |
| 16 | +By default every exception that is thrown in the PHP stack and not catched will be logged by the `symfony/monolog-bridge` on `error` level. |
| 17 | +But there are some cases where the exception is caused by clients accessing the API wrong (missing fields etc.) and throwing an `ShopwareHttpException` with a HTTP-Status-Code of 40x is our way of handling such situations and returning a correct HTTP-Status-Code to the client. |
| 18 | +So those cases are in fact no "errors" that need to be analyzed, but are expected given a malformed API request. |
| 19 | +Logging those cases as "errors" produces a lot of noice, which makes it harder to actually find errors in the logs. |
| 20 | + |
| 21 | +For our cloud product we already used a configuration list that configures that some Exception classes should only be logged as notices. |
| 22 | + |
| 23 | +## Decision |
| 24 | + |
| 25 | +We add configuration to the platform that degrades the error level of specific exceptions to notices. This way external hosters can also profit from our classification. |
| 26 | +We use [symfony's `exceptions` configuration](https://symfony.com/doc/current/reference/configuration/framework.html#exceptions) for this. |
| 27 | + |
| 28 | +This has the benefit that for specific projects this configuration could be adjusted, for example for cases where you also controll all clients that access the shop, you may want to log also every client error, just to help debugging the client. |
| 29 | + |
| 30 | +Another solution could be to do the configuration of the log level directly in the exception class either by attributes or a separate method specifying the log level, but that would make overwriting it for a specific project harder, so we stick to the default symfony configuration. |
| 31 | + |
| 32 | +## Consequences |
| 33 | + |
| 34 | +We will add the `exceptions` configuration to the platform, that way the error logging in existing projects might change. But in general we assume that this change is for the better. |
| 35 | + |
| 36 | +Additionally we will need to extend on the default symfony configuration as that is not compatible with our new [domain exceptions](./2022-02-24-domain-exceptions.md) as there are multiple exception cases in one file/class. |
| 37 | +Therefore we will add a similiar configuration option, that does not rely on the FQCN, but instead we will use the shopware specific `error code` from the shopware exception as that is unique to the exception case. |
| 38 | + |
| 39 | +On a side note we should be able to get rid of most the cloud specific configuration for the exception logging mapping. |
0 commit comments