# Plugin-Logger für SW 6

**URL:** <https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963>\
**Category:** Programmierung\
**Created:** [13. Januar 2020 um 09:37 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963 "2020-01-13T09:37:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![compragmbh](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@compragmbh](https://forum.shopware.com/u/compragmbh)\
**Post date:** [13. Januar 2020 um 09:37 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/1 "2020-01-13T09:37:50Z")

</div>

Hallo Zusammen,

Einfache Frage: Wie kann ich in einem SW 6 Plugin eine Message in das Logfile des Shops schreiben?  
In SW 5 gab es dazu den Plugin-Logger, den man sich über den DI-Container abholen konnte.

Wie funktioniert dies nun in SW 6?  
In der Doku habe ich bisher nur einen “Logging” Abschnitt zum Migration Assistent gefunden.  
&nbsp;

Viele Grüße  
Dennis

---

<div class="post-metadata">

**Author:** ![vanwittlaer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/vanwittlaer/32/8499_2.png) [@vanwittlaer](https://forum.shopware.com/u/vanwittlaer)\
**Post date:** [13. Januar 2020 um 10:16 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/2 "2020-01-13T10:16:28Z")

</div>

Hi Dennis,

ich nutz das&nbsp;

```
 Psr\Log\LoggerInterface

```

(wie auch schon in SW5), den ‚logger‘ Service kannst Du über die services.xml injecten.

Viel Erfolg,

Geert

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [13. Januar 2020 um 10:23 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/3 "2020-01-13T10:23:01Z")

</div>

Hallo Dennis,

hier siehst du an einem Beispiel, wie man sich ein plugin-spezifischen Logger erstellt: [SwagPayPal/util.xml at 1.10.0 · shopware/SwagPayPal · GitHub](https://github.com/shopware/SwagPayPal/blob/1.10.0/src/DependencyInjection/util.xml#L22-L25) Der Logger ist dann unter der ID „Swag\PayPal\Util\Logger“ im Container verfügbar und kann z.B. so injected werden: [SwagPayPal/client.xml at 1.10.0 · shopware/SwagPayPal · GitHub](https://github.com/shopware/SwagPayPal/blob/1.10.0/src/DependencyInjection/client.xml#L11)

Unter /var/log im Shopware Verzeichnis werden dann Dateien nach folgenden Schema angelegt: swag\_paypal\_dev-2020-01-10.log

Viele Grüße aus Schöppingen

Michael Telgmann

---

<div class="post-metadata">

**Author:** ![compragmbh](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@compragmbh](https://forum.shopware.com/u/compragmbh)\
**Post date:** [13. Januar 2020 um 10:42 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/4 "2020-01-13T10:42:31Z")

</div>

Perfekte Lösung, da die Logs so auch direkt in eine eigene Datei geschrieben werden!

&nbsp;

---

<div class="post-metadata">

**Author:** ![gaxweb](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gaxweb](https://forum.shopware.com/u/gaxweb)\
**Post date:** [21. März 2023 um 13:25 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/5 "2023-03-21T13:25:12Z")

</div>

Links sind tot. Hat jemand aktuelle? In den Docs finde ich zu eigenen Logs nichts.

Edit sagt: [Shopware 6 Custom Plugin Logger - Sindhi Tutorials](https://sindhitutorials.com/pages/shopware-6-custom-plugin-logger)

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [22. März 2023 um 12:19 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/6 "2023-03-22T12:19:45Z")

</div>

Hallo @gaxweb

danke für den Hinweis, ich hab die Links mal bearbeitet.

In der aktuellen Version sieht das wie folgt aus. [SwagPayPal/util.xml at 6.0.2 · shopware/SwagPayPal · GitHub](https://github.com/shopware/SwagPayPal/blob/6.0.2/src/Resources/config/services/util.xml#L31-L43)

Genutzt dann wie folgt: [SwagPayPal/client.xml at 6.0.2 · shopware/SwagPayPal · GitHub](https://github.com/shopware/SwagPayPal/blob/6.0.2/src/Resources/config/services/client.xml#L13)

Viele Grüße aus Schöppingen  
Michael Telgmann

---

<div class="post-metadata">

**Author:** ![gaxweb](https://avatars.discourse-cdn.com/v4/letter/g/ea5d25/32.png) [@gaxweb](https://forum.shopware.com/u/gaxweb)\
**Post date:** [8. Juli 2024 um 13:37 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/7 "2024-07-08T13:37:53Z")

</div>

Und wie ist das in SW 6.6? Ich werd aus den neuen Einträgen nicht wirklich schlau:

> <https://github.com/shopware/SwagPayPal/blob/ac9bff1d27198d2c4c86c9c2c37a8cda5b9f804f/src/Resources/config/services/util.xml#L33>

> <https://github.com/shopware/SwagPayPal/blob/ac9bff1d27198d2c4c86c9c2c37a8cda5b9f804f/src/Resources/config/services/client.xml#L15>

Genügt der Teil mit „introspection“ oder muss das darunter auch mit?

Wenn ich mir [How to Log Messages to different Files (Symfony Docs)](https://symfony.com/doc/current/logging/channels_handlers.html) anschaue, dann sollte es auch via PHP Attribut klappen, oder? Muss dann gar nichts in die services.xml? Wenn nicht, welcher Parameter im Konstruktor enthält dann den Logger?

---

<div class="post-metadata">

**Author:** ![R4M](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/r4m/32/9983_2.png) [@R4M](https://forum.shopware.com/u/R4M)\
**Post date:** [16. September 2024 um 10:26 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/8 "2024-09-16T10:26:47Z")

</div>

> [@vanwittlaer](#):
>
> ` Psr\Log\LoggerInterface`

Den Service benutze ich auch. Aber wo sehe ich die ausgeführten Logs unter SW 6.6? Muss das irgendwo noch extra definiert werden?

---

<div class="post-metadata">

**Author:** ![Moorleiche](https://avatars.discourse-cdn.com/v4/letter/m/6f9a4e/32.png) [@Moorleiche](https://forum.shopware.com/u/Moorleiche)\
**Post date:** [16. September 2024 um 10:57 UTC](https://forum.shopware.com/t/plugin-logger-fur-sw-6/63963/9 "2024-09-16T10:57:22Z")

</div>

Ich habe im Slack mal diesen Tipp bekommen. In der offiziellen Shopware Doku ist das sehr umständlich gelöst, man kann aber einen eigenen Service für „LoggerInterface“ registrieren.

```auto
<?xml version="1.0" encoding="UTF-8" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:monolog="http://symfony.com/schema/dic/monolog">
    <monolog:config>
        <monolog:channel>moorl_staging_channel</monolog:channel>
        <monolog:handler name="moorlStagingLogHandler"
                         type="rotating_file"
                         level="debug"
                         path="%kernel.logs_dir%/moorl_staging_%kernel.environment%.log">
            <monolog:channels>
                <monolog:channel>moorl_staging_channel</monolog:channel>
            </monolog:channels>
        </monolog:handler>
    </monolog:config>
</container>

```

Das Level ist hier statisch hinterlegt und steht auf „debug“ es wird also alles geloggt, unabhängig ob „prod“ oder „dev“.

In diesem Beispiel ist der Service, der als LoggerInterface dient:

```auto
<argument type="service" id="monolog.logger.moorl_staging_channel"/>

```
