smarter log cleanup script (#533)