Extracted logging and added log rotation