summaryrefslogtreecommitdiff
path: root/src/config.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-08-03 19:27:25 +0200
committermathieui <mathieui@mathieui.net>2013-08-03 19:27:25 +0200
commit31c2e23c4c3e2933952d5851bd5c97eb336258dd (patch)
treecb0ea7fe4d749c8a47e0457b42bbf9353fa24926 /src/config.py
parentc2f6ece39db14ba87ad33d6a7103193cf2e64050 (diff)
downloadpoezio-31c2e23c4c3e2933952d5851bd5c97eb336258dd.tar.gz
poezio-31c2e23c4c3e2933952d5851bd5c97eb336258dd.tar.bz2
poezio-31c2e23c4c3e2933952d5851bd5c97eb336258dd.tar.xz
poezio-31c2e23c4c3e2933952d5851bd5c97eb336258dd.zip
Logs errors by default, in a dedicated file
- log_errors option, true by default - errors go in log_dir/errors.log (so $XDG_DATA_HOME/errors.log by default) This should help a lot for debugging, and provide a way for people to easily give debug traces without useless or personal infos.
Diffstat (limited to 'src/config.py')
-rw-r--r--src/config.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/config.py b/src/config.py
index 34bbfe27..5eed4c09 100644
--- a/src/config.py
+++ b/src/config.py
@@ -22,7 +22,6 @@ from configparser import RawConfigParser, NoOptionError, NoSectionError
from os import environ, makedirs, path
from shutil import copy2
from args import parse_args
-from common import safeJID
class Config(RawConfigParser):
@@ -278,3 +277,59 @@ except:
sys.stderr.write('Poezio was unable to read or parse the config file.\n')
traceback.print_exc(limit=0)
sys.exit(1)
+
+LOG_DIR = config.get('log_dir', '') or path.join(environ.get('XDG_DATA_HOME') or path.join(environ.get('HOME'), '.local', 'share'), 'poezio')
+LOG_DIR = path.expanduser(LOG_DIR)
+
+try:
+ makedirs(LOG_DIR)
+except:
+ pass
+
+LOGGING_CONFIG = {
+ 'version': 1,
+ 'disable_existing_loggers': True,
+ 'formatters': {
+ 'simple': {
+ 'format': '%(levelname)s:%(module)s:%(message)s'
+ }
+ },
+ 'handlers': {
+ 'debug':{
+ 'level':'DEBUG',
+ 'class':'logging.FileHandler',
+ 'filename': '/tmp/dummy',
+ 'formatter': 'simple',
+ },
+ 'error': {
+ 'level': 'ERROR',
+ 'class': 'logging.FileHandler',
+ 'filename': '/tmp/dummy',
+ 'formatter': 'simple',
+ },
+ },
+ 'root': {
+ 'handlers': [],
+ 'propagate': True,
+ 'level': 'DEBUG',
+ }
+}
+if config.get('log_errors', 'true').lower() != 'false':
+ LOGGING_CONFIG['root']['handlers'].append('error')
+ LOGGING_CONFIG['handlers']['error']['filename'] = path.join(
+ LOG_DIR,
+ 'errors.log')
+
+if options.debug:
+ LOGGING_CONFIG['root']['handlers'].append('debug')
+ LOGGING_CONFIG['handlers']['debug']['filename'] = options.debug
+
+if LOGGING_CONFIG['root']['handlers']:
+ logging.config.dictConfig(LOGGING_CONFIG)
+else:
+ logging.basicConfig(level=logging.CRITICAL)
+
+# common import sleekxmpp, which creates then its loggers, so
+# it needs to be after logger configuration
+from common import safeJID
+