Fix memory leak by cleaning up logging code.
Fix memory leak by cleaning up logging code.