fixed a bug when log file creation failed

1. handle the case when log folder creation failure
2. only set log handler after log file opened successfully
Merge pull request #379 from haiwen/handle-log-file-creation-failure

fixed a bug when log file creation failed