how to empty
.log file in Magento 2 from Terminal ?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.Sign up to join this community
You can remove the log files from terminal using below command, it will not create any issue as log files again generated in var/log;
rm -rf magento_root/var/log/*;
For removing log files everyday i suggest create a cron on server using below code:
0 0 * * 0-6 cd /magento_root/; rm -rf var/log/*
Above cron will run everyday at 12:00 AM. Let me know if this is not working.
As the other answers have pointed out, since the logs are autogenerated removing them should be fine. Although this will override any permission etc you set on the files.
If you are purley looking to empty the file you can use the truncate command.
truncate -s0 /var/www/site.com/var/log/exception.log
As a side note, if you are wanting to periodically empty logs. Then i would recommend setting up and configuring
LogRotate. This will allow you to compress the old logs and store them for a set amount of time before scrapping them.
See the following thread on using LogRotate Limiting the size of system.log and exception.log files