Skip to content
Snippets Groups Projects
Commit bca5fdeb authored by BRONES Romain's avatar BRONES Romain
Browse files

(cli): Catch exception FileNotFoundError for FileHandler

parent b7646d5c
Branches
No related tags found
No related merge requests found
...@@ -29,7 +29,12 @@ if __name__ == '__main__': ...@@ -29,7 +29,12 @@ if __name__ == '__main__':
logger.addHandler(sh) logger.addHandler(sh)
# Add a file handler # Add a file handler
fh=logging.FileHandler("/home/data/DG/FOFB/FofbTool.log") logpath="/home/data/DG/FOFB/FofbTool.log"
try:
fh=logging.FileHandler(logpath)
except FileNotFoundError:
logger.warning("Not logging to file, could not open location {}".format(logpath))
else:
fh.setLevel(logging.DEBUG) fh.setLevel(logging.DEBUG)
fh.setFormatter(logging.Formatter("{levelname:8}: {message}", style='{')) fh.setFormatter(logging.Formatter("{levelname:8}: {message}", style='{'))
logger.addHandler(fh) logger.addHandler(fh)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment