How to Configure Separate Log Files in Shopware 6.5 Production Environment

In the production environment of Shopware 6.5, it’s essential to manage logs efficiently for debugging and monitoring purposes. By default, Shopware logs are consolidated into a single file. This might not be ideal for large-scale applications or when you need to isolate logs for different components. This guide will walk you through the process of configuring separate log files for specific functionalities or plugins in your Shopware 6.5 installation.

Procedure

To configure separate log files in the production environment of Shopware 6.5, follow these steps:

1. Locate the `services.xml` file in your plugin directory 

  •     Access your Shopware 6.5 installation directory.
  •     Navigate to the `src/Resources/config/services.xml` file.

2. Update the `services.xml` file

  •     Open the `services.xml` file using a text editor of your choice.
  •     Look for the `<services>` section within the file.

3. Add service definitions for separate log files

  •     Insert the following XML snippet into the `services.xml` file:
xml

   <service id="plugin-name.plugin.logger" class="Monolog\Logger">

       <argument type="string">plugin-name</argument>

       <argument type="collection">

           <argument type="service" id="plugin-name.plugin.rotatingHandler"/>

       </argument>

   </service>

   <service id="stonelab-plytix.plugin.rotatingHandler" class="Monolog\Handler\RotatingFileHandler">

       <argument type="string">%kernel.logs_dir%/plugin-name-%kernel.environment%.log</argument>

   </service>

4. Save the changes

    Save the `services.xml` file after adding the service definitions.

5. Give it as argument for the needed services

<argument type=”service” id=”plugin-name.plugin.logger”/>

6. Access this variable and write the log inside it.

    use Psr\Log\LoggerInterface $logger

    $this->logger->info(“log information”)

7. Clear the cache

  •     Access your Shopware installation via SSH or FTP.
  •     Run the following command to clear the cache:

   “`bash

   bin/console cache:clear

   This step ensures that the changes made to the `services.xml` file take effect.

8. Verify the configuration

  •     Check the specified log directory to ensure that separate log files are created based on the configuration.
  •     You should see log files named according to the specified pattern, such as `plugin-name-production.log` for the production environment.

Conclusion

Configuring separate log files in the production environment of Shopware 6.5 allows you to organise and manage your logs more efficiently. By following the steps outlined in this guide and updating the `services.xml` file with the provided configuration, you can tailor your logging setup to meet the specific requirements of your Shopware installation.

Comments are closed.

2hats Logic HelpBot