How to create your own log file in magento

How to create your own log file in magento

September 24, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to create your own log file in magento

Creating Your Own Log File in Magento

Welcome to your first steps into the world of Magento development! One of the most common tasks you’ll find yourself doing is logging important data for debugging purposes or tracking user activity. Let’s walk through how to create and use a custom log file in Magento.

Understanding Magento’s Logging System

Magento has a robust built-in logging system that allows you to record messages at different levels of severity: debug, info, notice, warning, error, critical, alert, and emergency. By default, these logs are stored in the var/log directory following the format of {Component}_{Type}.log.

Creating Your Custom Log File

To create your own log file in Magento, you’ll need to use the built-in logging facilities provided by the framework. Here’s a step-by-step guide:

  1. Enable a custom log channel: Open your app/etc/config.xml file and add a new <logs> node under the <config> element:
<config>
    <global>
        <!-- ... existing config elements ... -->
        <logs>
            <custom_log>
                <active>true</active>
                <log_dir>var/log</log_dir>
                <log_file>custom.log</log_file>
            </custom_log>
        </logs>
    </global>
</config>
  1. Configure the log channel: Open your app/code/core/Mage/Log/etc/config.xml file and add the following inside the <global> element:
<global>
    <resources>
        <!-- ... existing resources ... -->
    </resources>
    <logs>
        <custom_log>
            <active>true</active>
            <log_dir>var/log</log_dir>
            <log_file>custom.log</log_file>
        </custom_log>
    </logs>
</global>
  1. Write to the custom log file: Now you can use Magento’s logging methods from anywhere in your code:
// Use Mage::log() to write a message to the custom log file
Mage::log('This is a test log entry for my custom log file', null, 'custom.log');

Best Practices and Additional Tips

Remember that writing to logs can have performance implications. Only log when necessary and avoid logging sensitive or large amounts of data.

If you’re working with third-party extensions, check their documentation to see if they provide any logging options. Many extensions support custom logs through configuration files.

For more advanced logging needs, consider using Magento’s logger design pattern which allows for greater control over the logging process. You can find detailed information on this in the [Laravel Company blog][1].

Conclusion

Creating a custom log file in Magento is an essential skill every developer should have in their toolkit. By following these steps and understanding how to leverage the built-in logging system, you’ll be well-equipped to debug issues, monitor system health, and track important events in your e-commerce application.

Remember that clear and concise logging can save hours of debugging time down the line. Don’t hesitate to create a custom log file whenever you need more detailed information about what’s happening behind the scenes.

Happy coding!

[1] Advanced Logging Techniques in Magento

Configuration Import/Export Errors

Our network