diff options
author | Andrew Resch <andrewresch@gmail.com> | 2009-01-16 00:35:07 +0000 |
---|---|---|
committer | Andrew Resch <andrewresch@gmail.com> | 2009-01-16 00:35:07 +0000 |
commit | f16ff06083edbeb3ced3dc765ea65830938e5bac (patch) | |
tree | 8708f7ffab9e980db859e30fe8b829d4d9034a73 /deluge/log.py | |
parent | f990fd1a9a7e0abae83b9d077a35d6a7abb8f631 (diff) | |
download | deluge-f16ff06083edbeb3ced3dc765ea65830938e5bac.tar.gz deluge-f16ff06083edbeb3ced3dc765ea65830938e5bac.tar.bz2 deluge-f16ff06083edbeb3ced3dc765ea65830938e5bac.zip |
Fix the -l, --logfile option
Diffstat (limited to 'deluge/log.py')
-rw-r--r-- | deluge/log.py | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/deluge/log.py b/deluge/log.py index 2f415158c..be2244c02 100644 --- a/deluge/log.py +++ b/deluge/log.py @@ -27,12 +27,32 @@ import logging -# Setup the logger -logging.basicConfig( - level=logging.ERROR, - format="[%(levelname)-8s] %(asctime)s %(module)s:%(lineno)d %(message)s", - datefmt="%H:%M:%S" -) +levels = { + "info": logging.INFO, + "warning": logging.WARNING, + "error": logging.ERROR, + "none": logging.CRITICAL, + "debug": logging.DEBUG +} +def setupLogger(level="error", filename=None): + """ + Sets up the basic logger and if `:param:filename` is set, then it will log + to that file instead of stdout. + + :param level: str, the level to log + :param filename: str, the file to log to + """ + + if not level: + level = "error" + + logging.basicConfig( + level=levels[level], + format="[%(levelname)-8s] %(asctime)s %(module)s:%(lineno)d %(message)s", + datefmt="%H:%M:%S", + filename=filename, + filemode="w" + ) def setLoggerLevel(level): """ @@ -41,14 +61,6 @@ def setLoggerLevel(level): :param level: str, a string representing the desired level """ - levels = { - "info": logging.INFO, - "warning": logging.WARNING, - "error": logging.ERROR, - "none": logging.CRITICAL, - "debug": logging.DEBUG - } - if level not in levels: return |