summaryrefslogtreecommitdiff
path: root/src/logger.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-04-05 23:57:53 +0200
committermathieui <mathieui@mathieui.net>2013-04-05 23:57:53 +0200
commit91b960b797bbf17f6c4b33279f2d406c5a2c93b2 (patch)
tree91cbb61f2618d448416f4a41043ef2327793a53b /src/logger.py
parent16268ba96460c0947be7208cba60ad95270a4da7 (diff)
downloadpoezio-91b960b797bbf17f6c4b33279f2d406c5a2c93b2.tar.gz
poezio-91b960b797bbf17f6c4b33279f2d406c5a2c93b2.tar.bz2
poezio-91b960b797bbf17f6c4b33279f2d406c5a2c93b2.tar.xz
poezio-91b960b797bbf17f6c4b33279f2d406c5a2c93b2.zip
Handle I/O errors better
- Do not crash because of low disk space - Notify the user whenever it happens - A few functions now return a boolean instead of nothing - Config.silent_set is Config.set_and_save without toggle and returning strings. It is used whenever we don’t need set_and_save - Config.set_and_save now returns a tuple (that can be passed directly to core.information()) TODO: display the precise error to the user (instead of “unable to…”)
Diffstat (limited to 'src/logger.py')
-rw-r--r--src/logger.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/logger.py b/src/logger.py
index 8b4b1d3c..a696137f 100644
--- a/src/logger.py
+++ b/src/logger.py
@@ -32,7 +32,10 @@ class Logger(object):
def __del__(self):
for opened_file in self.fds.values():
if opened_file:
- opened_file.close()
+ try:
+ opened_file.close()
+ except: # Can't close? too bad
+ pass
def reload_all(self):
"""Close and reload all the file handles (on SIGHUP)"""
@@ -106,7 +109,7 @@ class Logger(object):
else:
fd = self.check_and_create_log_dir(jid)
if not fd:
- return
+ return True
try:
msg = clean_text(msg)
if date is None:
@@ -117,18 +120,26 @@ class Logger(object):
fd.write(''.join((str_time, nick, ': ', msg, '\n')))
else:
fd.write(''.join((str_time, '* ', msg, '\n')))
- except IOError:
- pass
+ except:
+ return False
else:
- fd.flush() # TODO do something better here?
+ try:
+ fd.flush() # TODO do something better here?
+ except:
+ return False
+ return True
def log_roster_change(self, jid, message):
if not self.roster_logfile:
try:
self.roster_logfile = open(os.path.join(DATA_HOME, 'logs', 'roster.log'), 'a')
except IOError:
- return
- self.roster_logfile.write('%s %s %s\n' % (datetime.now().strftime('%d-%m-%y [%H:%M:%S]'), jid, message))
- self.roster_logfile.flush()
+ return False
+ try:
+ self.roster_logfile.write('%s %s %s\n' % (datetime.now().strftime('%d-%m-%y [%H:%M:%S]'), jid, message))
+ self.roster_logfile.flush()
+ except:
+ return False
+ return True
logger = Logger()