[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

How to delete logs with Windows Apache log rotation

My name is Ito and I am an infrastructure engineer.

Logrotate is used to configure Apache log rotation on Linux.

For more information on log rotation, please see here.
Try using log rotation (logrotate) (httpd (apache) configuration example) | Tips for setting up and building a rental server/home server

By the way, I looked into how log rotation works in Windows, and found that
logs are rotated using "rotatelogs.exe" that comes with Windows Apache, but it seems that they cannot be deleted.

This is how to delete old logs after rotation.

Check Apache log settings

Configure the Apache log file output settings in "httpd.conf".
Change the log output settings on a daily basis.

#Original settings ErrorLog "|bin/rotatelogs.exe logs/error-%Y%m%d-%H.log 10M -l" CustomLog "|bin/rotatelogs.exe logs/access-%Y%m%d- %H.log 10M -l" common #After setting changes ErrorLog "| bin/rotatelogs.exe logs/error_%Y%m%d.log 86400" CustomLog "| bin/rotatelogs.exe logs/access_%Y%m% d.log 86400" common

The original setting is "Rotate when the log reaches 10MB", so
change it to "Rotate every 86400 seconds (1 day)".

If you are using Linux, logrotate will even delete the logs if you configure the settings, but
if you are using Windows, you will need to do something more.

Create a batch file

It is possible to delete old rotated files by creating a batch file and running the batch periodically.

forfiles /P "D:\Apache\logs" /D -7 /C "cmd /c del @file"

Use the "forfiles" command to extract files that match the conditions.
The meaning of each argument is as follows.

argument explanation
/P Target path
/D Extract based on file modification date (-7 means 7 days ago)
/C Execute another command on the output file (cmd command in this case)
@file Variable of the extracted file (@ext is a variable that represents the extension of the extracted file)

By creating a batch file like this and registering it in the task scheduler,
you can delete files from x days ago from the rotated files.

possible to compress old logs by using a compression command (such as 7zip) instead of the del command The combinations are endless.

If you found this article helpful , please give it a like!
1
Loading...
1 vote, average: 1.00 / 11
21,111
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author