Health and maintenance · Magento 2

Magento 2 log rotation: stop log files from filling up your store's disk

Magento records every error in files that are never emptied. Months later they can weigh several gigabytes and take your store down. Here is how to check the size of your logs in two minutes, what to ask your hosting provider, and how to set up log rotation to fix the problem for good.

Illustration: the orange Tocsin24 bell rings above a server overflowing with log sheets, next to a blue archive box.

In short

  • Magento writes its errors to files in the var/log folder and never empties them.
  • An FTP client is enough to check their size. Above 500 MB, log rotation is not in place.
  • Log rotation archives these files every night and deletes the oldest ones. It is a server setting, done once.
  • A file that grows very fast often points to a recurring error that needs fixing.
Contents

Why Magento 2 logs keep growing

A log file is your store’s logbook, on Magento 2 and Adobe Commerce alike. Each time something goes wrong, Magento adds a line: a payment declined by the bank, a crashing extension, a missing product. These notes are precious when you need to understand an outage.

The catch is that Magento never tears out the old pages. It keeps writing at the end, day after day. The two files that grow the most are usually system.log and exception.log. The second one holds the full details of every error and is often the heaviest.

Disk usage of a store

100 GB disk, logs growing by 2.5 GB a week

Illustration
Without log rotation Full in 18 weeks
With log rotation 56% stable
Critical Watch 40% 60% 80% 100% wk 0 wk 4 wk 8 wk 12 wk 16 wk 20 Disk full, wk 18 Critical Watch 40% 60% 80% 100% wk 0 wk 5 wk 10 wk 15 wk 20 Disk full, wk 18
Show the values
WeekWithout log rotationWith log rotation
0 55% 56%
4 65% 56%
8 75% 56%
12 84% 56%
16 95% 56%
18 100% (full) 56%
20 100% (full) 56%
Without rotation, the disk ends up full. With a full disk, the store goes down: the database can no longer save orders, and backups fail.
For developers

Magento logs through Monolog. Its handler, Magento\Framework\Logger\Handler\Base, extends Monolog’s StreamHandler: it appends to the file and has no built-in rotation. Monolog recommends leaving rotation to the system tool, logrotate.

Check the size of Magento logs in var/log

No technical skills needed. Connect to your store with an FTP or SFTP client (FileZilla, Cyberduck, WinSCP), or with your hosting provider’s file manager. Your hosting provider or agency gave you the credentials.

  1. Open the Magento folder, the one that contains app, pub and var.
  2. Go into var, then into log.
  3. Look at the Size column.
/var/www/store/var/log
NameSizeModified
..
cron.log 212 MB today 09:41
debug.log 3 MB 12/03/2026
exception.log 1.8 GB today 09:40
system.log 640 MB today 09:41
Example. Files of several hundred megabytes, going back months: log rotation is not in place.

How to read the sizes. A few megabytes, even a few dozen, is normal. Above 500 MB for system.log or exception.log, log rotation is almost certainly not in place.

Log rotation, in plain words

Every night, the server sets aside the previous day’s file, compresses it and starts a fresh, empty file. Archives that are too old, for example more than two weeks old, are deleted. The total size stays stable, and you keep enough history to investigate a recent incident.

  1. Today system.log Magento writes here
  2. Yesterday system.log.1 Readable archive
  3. Day before system.log.2.gz Compressed archive, much lighter
  4. … system.log.14.gz Last archive kept
  5. 15 days system.log.15.gz Deleted
What you will see in the folder once rotation is in place: one current file and a series of numbered archives.

Not technical? What to ask your hosting provider

Log rotation is set up on the server. That is the job of your hosting provider, your agency or whoever manages the server. Many Magento hosting providers already have a tool for it: asking is often enough. Here is a message ready to send:

Message to your hosting provider or agency

Hello,

The log files of our Magento store (var/log/system.log and var/log/exception.log) keep growing without limit: exception.log is now over 1 GB.

Could you set up rotation for the Magento logs: nightly archiving and compression, with 14 days kept?

Could you also check whether an error keeps repeating in exception.log?

Thank you.

You manage the server: configure logrotate for Magento on Debian or Ubuntu

On Debian and Ubuntu, logrotate is part of the standard installation and runs once a day, shortly after midnight. It already rotates the system and web server logs, but not Magento’s. You just need to add one file.

  1. Find the owner of the log folder. Rotation will run as this user. Replace the path with your store’s:

    Terminal
    stat -c '%U %G' /var/www/store/var/log

    The answer is, for example, www-data www-data.

  2. Create the file /etc/logrotate.d/magento with this content, adjusting the path and the user:

    Content of /etc/logrotate.d/magento
    1. /var/www/store/var/log/*.log {
    2. su www-data www-data
    3. daily
    4. rotate 14
    5. missingok
    6. notifempty
    7. compress
    8. delaycompress
    9. copytruncate
    10. }

    What each line means:

    • Line 1 Every .log file in Magento's log folder. Replace the path with your store's.
    • su Run as the owner of the folder, the answer from step 1.
    • daily, rotate 14 One rotation a day, fourteen archives kept, so two weeks of history.
    • missingok, notifempty Do not stop if a file is missing, and leave empty files alone.
    • compress, delaycompress Compress the archives, except the previous day's, which stays readable as is.
    • copytruncate Copy the file, then empty it in place instead of moving it (see the box below).
  3. Check the configuration without changing anything, then run a first rotation:

    Terminal
    Dry run: shows what would be done, without changing anything sudo logrotate -d -f /etc/logrotate.d/magento First rotation, right now, then check sudo logrotate -f /etc/logrotate.d/magento ls -lh /var/www/store/var/log/

    The dry run should print log needs rotating for each file, then copying and truncating. After the real rotation, you should see system.log back to zero and a copy named system.log.1. Without this first manual rotation, logrotate would only record the files on the first night and start rotating them the night after. From then on, it takes care of it on its own.

A file that grows too fast often hides an error

Rotation limits the space used, but it does not tell you why a file grows. An error repeated on every page view can fill exception.log in a few hours. It can also slow the store down or get in the way of purchases. If a file grows past 500 MB in a single day, have your developer open it and look for the recurring error.

Another common cause is the debug log, which fills debug.log. Adobe turns it on by default as long as the store is not in production mode, and it is sometimes switched on while troubleshooting and then forgotten. In production, it must be off:

Terminal, from the Magento folder
bin/magento setup:config:set --enable-debug-logging=false bin/magento cache:flush

Empty or delete Magento logs by hand?

Emptying a large log over FTP helps on the day, with no risk for the store: Magento keeps writing into the emptied file. Deleting it works less well: as long as a background process keeps the file open, the space only comes back when that process stops. Either way, the problem comes back. Only rotation solves it for good.

Tocsin24 warns you before the disk is full

Tocsin24 regularly records the free space on your store’s server and works out how fast it is filling up. It also reads system.log and exception.log to group your store’s errors, and warns you as soon as one of these files goes past 500 MB.

Espace disque

Espace libre sur le serveur du site.

Disque du serveur racine du site À surveiller
16 Go libres sur 100 Go 84 % utilisé
+2,5 Go par semaine · plein dans environ 6 semaines Relevé le 23/10 09:00

Erreurs de l'application

Logs Magento lus par le module Tocsin24, sans accès à créer chez votre hébergeur.

Récupérés
  • var/log/system.log 42 Mo écrit il y a 2 min
  • var/log/exception.log 1,8 Go écrit il y a 3 min Rotation absente
exception.log fait 1,8 Go et remonte au 4 mars 2025 : la rotation des logs n'est pas en place.

Nous en lisons seulement les lignes récentes : la détection n'est pas gênée. Pour éviter de saturer le disque de la boutique, demandez à votre hébergeur ou à votre agence d'activer la rotation des logs Magento (archivage et compression réguliers).

Application screens with example values.

Frequently asked questions

Can log rotation break my store?

No. It only touches the log files, which Magento recreates on its own. The store keeps running during rotation.

Can I turn off system.log or exception.log?

Magento has no setting for that, and you would lose the only record of an outage. Only the debug log can be turned off. For the others, rotate the files and fix recurring errors.

How many days of history should I keep?

Two weeks is usually enough to understand an incident. Keep more if a contract requires it, while keeping an eye on the space the archives take.

Is a Magento log rotation extension good enough?

Some exist, but they depend on Magento's cron, so when cron is down, rotation stops too. logrotate runs outside Magento, and it is the tool recommended by Monolog, the logging library Magento uses.

My disk is filling up but the logs are small. What should I check?

The var/report folder, which keeps one file per error shown to visitors, backups left on the server, and the web server logs. Your hosting provider can tell you which folder takes the most space.

Portrait of Cédric Michel

Cédric Michel

Cédric has been building Magento stores for 18 years and holds the Adobe Commerce Developer Expert certification. He created Tocsin24 to monitor the security and health of Magento 2 stores and WordPress sites.

Adobe Commerce Developer Expert badge Adobe Commerce Developer Expert
Verify the certification on Adobe’s website

Sources

  1. Adobe Commerce: enable or disable logging
  2. logrotate manual (logrotate 8)
  3. Magento source code: Logger\Handler\Base
  4. Monolog source code: RotatingFileHandler (“Using logrotate to handle the rotation is strongly encouraged”)
  5. Debian: logrotate package