diff --git a/CHANGELOG b/CHANGELOG index c17e0257..f060a50e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ http://codingteam.net/project/poezio/roadmap - default nickname is now $USER - Server on /join command can be omitted - /query command can now take a message in parameters +- logs are now save in $XDG_DATA_HOME and this can be configured * Poezio 0.6.1 - 13 Jun 2010 - Enable tracebacks diff --git a/data/default_config.cfg b/data/default_config.cfg index 8de84037..cfe00206 100644 --- a/data/default_config.cfg +++ b/data/default_config.cfg @@ -75,9 +75,14 @@ hide_exit_join = -1 hide_status_change = 120 # set to 'true' if you want to save logs of all the messages -# in files. They will be saved in ~/.config/poezio/logs +# in files. use_log = false +# If log_dir is not set, logs will be saved in $XDG_DATA_HOME/poezio/logs, +# i.e. in ~/.local/share/poezio/logs. So, you should specify the directory +# you want to use instead. This directory will be created if it doesn't exist +log_dir = + # the full path to the photo (avatar) you want to use # it should be less than 16Ko # The avatar is not set by default, because it slows diff --git a/src/logging.py b/src/logging.py index 42a82760..a3321cdf 100644 --- a/src/logging.py +++ b/src/logging.py @@ -22,10 +22,10 @@ from os import environ, makedirs from datetime import datetime from config import config -CONFIG_HOME = environ.get("XDG_CONFIG_HOME") -if not CONFIG_HOME: - CONFIG_HOME = environ.get('HOME')+'/.config' -CONFIG_PATH = CONFIG_HOME + '/poezio/' +DATA_HOME = config.get('log_dir', environ.get("XDG_DATA_HOME")) +if not DATA_HOME: + DATA_HOME = environ.get('HOME')+'/.local/share' +DATA_PATH = DATA_HOME + '/poezio/' class Logger(object): """ @@ -63,11 +63,15 @@ class Logger(object): """ if config.get('use_log', 'false') == 'false': return - dir = CONFIG_PATH+'logs/' + dir = DATA_PATH+'logs/' try: makedirs(dir) - except:pass - fd = open(dir+room, 'a') + except OSError: + pass + try: + fd = open(dir+room, 'a') + except IOError: + return if nick: fd.write(datetime.now().strftime('%d-%m-%y [%H:%M:%S] ')+nick.encode('utf-8')+': '+msg.encode('utf-8')+'\n') else: