logs are now xdg compliant, fixed #1520

This commit is contained in:
louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 2010-07-01 22:01:09 +00:00
parent 2b19ec1cff
commit 432bab0b6b
3 changed files with 18 additions and 8 deletions

View file

@ -8,6 +8,7 @@ http://codingteam.net/project/poezio/roadmap
- default nickname is now $USER - default nickname is now $USER
- Server on /join command can be omitted - Server on /join command can be omitted
- /query command can now take a message in parameters - /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 * Poezio 0.6.1 - 13 Jun 2010
- Enable tracebacks - Enable tracebacks

View file

@ -75,9 +75,14 @@ hide_exit_join = -1
hide_status_change = 120 hide_status_change = 120
# set to 'true' if you want to save logs of all the messages # 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 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 # the full path to the photo (avatar) you want to use
# it should be less than 16Ko # it should be less than 16Ko
# The avatar is not set by default, because it slows # The avatar is not set by default, because it slows

View file

@ -22,10 +22,10 @@ from os import environ, makedirs
from datetime import datetime from datetime import datetime
from config import config from config import config
CONFIG_HOME = environ.get("XDG_CONFIG_HOME") DATA_HOME = config.get('log_dir', environ.get("XDG_DATA_HOME"))
if not CONFIG_HOME: if not DATA_HOME:
CONFIG_HOME = environ.get('HOME')+'/.config' DATA_HOME = environ.get('HOME')+'/.local/share'
CONFIG_PATH = CONFIG_HOME + '/poezio/' DATA_PATH = DATA_HOME + '/poezio/'
class Logger(object): class Logger(object):
""" """
@ -63,11 +63,15 @@ class Logger(object):
""" """
if config.get('use_log', 'false') == 'false': if config.get('use_log', 'false') == 'false':
return return
dir = CONFIG_PATH+'logs/' dir = DATA_PATH+'logs/'
try: try:
makedirs(dir) makedirs(dir)
except:pass except OSError:
fd = open(dir+room, 'a') pass
try:
fd = open(dir+room, 'a')
except IOError:
return
if nick: if nick:
fd.write(datetime.now().strftime('%d-%m-%y [%H:%M:%S] ')+nick.encode('utf-8')+': '+msg.encode('utf-8')+'\n') fd.write(datetime.now().strftime('%d-%m-%y [%H:%M:%S] ')+nick.encode('utf-8')+': '+msg.encode('utf-8')+'\n')
else: else: