diff options
author | Mathieu Blondel <mathieu@mblondel.org> | 2007-05-19 16:52:55 +0000 |
---|---|---|
committer | Mathieu BlondelMathieu Blondel <mathieu@mblondel.orgmathieu@mblondel.org> | 2007-05-19 16:52:55 +0000 |
commit | d954adae8eceec5cd5ee6e439a652a2d1323e5a4 (patch) | |
tree | 9be5568ad8f94000b369cef0a739ef07346e8937 /src | |
parent | 7dba8bd667fbb9fc5624e0b1e30e4c85e700fe1d (diff) | |
download | wikipediafs-d954adae8eceec5cd5ee6e439a652a2d1323e5a4.tar.gz |
- Added a debug mode option in the config.
- Set debug logging level if debug mode set in config.
git-svn-id: http://svn.code.sf.net/p/wikipediafs/code/branches/fuse-python-new-api@28 59acd704-e115-0410-a914-e735a229ed7c
Diffstat (limited to 'src')
-rw-r--r-- | src/wikipediafs/config.py | 15 | ||||
-rw-r--r-- | src/wikipediafs/logger.py | 46 |
2 files changed, 60 insertions, 1 deletions
diff --git a/src/wikipediafs/config.py b/src/wikipediafs/config.py index 5ad5941..0da7bfd 100644 --- a/src/wikipediafs/config.py +++ b/src/wikipediafs/config.py @@ -86,6 +86,8 @@ class Config: self.__config = minidom.parseString(config_str).documentElement self.__setCacheTime() + + self.__setDebug() self.__setSites() @@ -129,15 +131,25 @@ class Config: self.cache_time = val except: self.cache_time = 300 + + def __setDebug(self): + element = self.__config.getElementsByTagName("debug") + if element.length == 0: + self.debug_mode = False + else: + self.debug_mode = True -if __name__ == "__main__": +if __name__ != "__main__": + config = Config() +else: config_test = """\ <?xml version="1.0" encoding="UTF-8"?> <wfs-config> <general> <!-- Cache time in seconds --> <article-cache-time>300</article-cache-time> + <debug /> </general> <sites> <site> @@ -160,5 +172,6 @@ if __name__ == "__main__": config = Config(config_test) print "cache time:", config.cache_time + print "debug:", config.debug_mode for k, v in config.sites.items(): print k, v
\ No newline at end of file diff --git a/src/wikipediafs/logger.py b/src/wikipediafs/logger.py new file mode 100644 index 0000000..60d88e7 --- /dev/null +++ b/src/wikipediafs/logger.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# WikipediaFS +# Copyright (C) 2005 - 2007 Mathieu Blondel +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +import logging +import os, os.path +from config import config + +conf_dir = os.path.join(os.environ['HOME'], '.wikipediafs') +file = os.path.join(conf_dir, 'wikipediafs.log') + +# Creates .wikipediafs. in HOME if needed +if not os.path.exists(conf_dir): + os.mkdir(conf_dir,0700) + +logger = logging.getLogger('wikipediafs') +hdlr = logging.FileHandler(file) +formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') +hdlr.setFormatter(formatter) +logger.addHandler(hdlr) + +if config.debug_mode: + logger.setLevel(logging.DEBUG) +else: + logger.setLevel(logging.INFO) + +# logger.debug('A debug message') +# logger.info('Some information') +# logger.warning('A shot across the bows') +# logger.error('error...') |