Move logging code to its own file