try/except inside loop

to make scope more obvious. Also renamed file to _file to avoid conflict
with builtin functions
Logging msg using PEP3103 formatter