Moved log related code to its own file