There's already a package called logrotate to do that. It's driven from /etc/logrotate.conf and the files in /etc/logrotate.d
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.
Any DMs sent on Twitter will be answered next month.
This is a doctor free zone.