From cc74576c9f5a77128db99468a8432c7de8100302 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 21 Feb 2011 21:00:23 +0100 Subject: Avoid crash when write to log file fails --- src/logger.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/logger.py b/src/logger.py index d2a00eaa..4078c46a 100644 --- a/src/logger.py +++ b/src/logger.py @@ -69,10 +69,14 @@ class Logger(object): fd = self.check_and_create_log_dir(jid) if not fd: return - if nick: - fd.write(datetime.now().strftime('%d-%m-%y [%H:%M:%S] ')+nick+': '+msg+'\n') + try: + if nick: + fd.write(datetime.now().strftime('%d-%m-%y [%H:%M:%S] ')+nick+': '+msg+'\n') + else: + fd.write(datetime.now().strftime('%d-%m-%y [%H:%M:%S] ')+'* '+msg+'\n') + except IOError: + pass else: - fd.write(datetime.now().strftime('%d-%m-%y [%H:%M:%S] ')+'* '+msg+'\n') - fd.flush() # TODO do something better here? + fd.flush() # TODO do something better here? logger = Logger() -- cgit v1.2.3