Skip to content

Commit ad4c09f

Browse files
author
Alexander Smishlajev
committed
added logging support;
fix FilePathOption: empty values are empty, not a relative directory paths.
1 parent 69ed96a commit ad4c09f

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

roundup/configuration.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Roundup Issue Tracker configuration support
22
#
3-
# $Id: configuration.py,v 1.1 2004-07-25 11:29:40 a1s Exp $
3+
# $Id: configuration.py,v 1.2 2004-07-25 12:44:16 a1s Exp $
44
#
55
__docformat__ = "restructuredtext"
66

@@ -9,6 +9,7 @@
99
import time
1010
import ConfigParser
1111

12+
from roundup import instance, rlog
1213
# XXX i don't think this module needs string translation, does it?
1314

1415
### Exceptions
@@ -287,7 +288,7 @@ class FilePathOption(Option):
287288

288289
def get(self):
289290
_val = Option.get(self)
290-
if not os.path.isabs(_val):
291+
if _val and not os.path.isabs(_val):
291292
_val = os.path.join(self.config["TRACKER_HOME"], _val)
292293
return _val
293294

@@ -384,6 +385,21 @@ def set(self, value):
384385
(MailAddressOption, "email", "issue_tracker",
385386
"Email address that mail to roundup should go to"),
386387
)),
388+
("logging", (
389+
(FilePathOption, "config", "",
390+
"Path to configuration file for standard Python logging module.\n"
391+
"If this option is set, logging configuration is loaded\n"
392+
"from specified file; options 'filename' and 'level'\n"
393+
"in this section are ignored."),
394+
(FilePathOption, "filename", "",
395+
"Log file name for minimal logging facility built into Roundup.\n"
396+
"If no file name specified, log messages are written on stderr.\n"
397+
"If above 'config' option is set, this option has no effect."),
398+
(Option, "level", "ERROR",
399+
"Minimal severity level of messages written to log file.\n"
400+
"If above 'config' option is set, this option has no effect.\n"
401+
"Allowed values: DEBUG, INFO, WARNING, ERROR"),
402+
)),
387403
# XXX This section covers two service areas:
388404
# outgoing mail (domain, smtp parameters)
389405
# and creation of issues from incoming mail.
@@ -479,6 +495,8 @@ class Config:
479495
section_options = None
480496
# mapping from option names and aliases to Option instances
481497
options = None
498+
# logging engine
499+
logging = rlog.BasicLogging()
482500

483501
def __init__(self, tracker_home=None):
484502
# initialize option containers:
@@ -495,6 +513,8 @@ def __init__(self, tracker_home=None):
495513
# load the config if tracker_home given
496514
if tracker_home is not None:
497515
self.load(tracker_home)
516+
else:
517+
self.init_logging()
498518

499519
def add_option(self, option):
500520
"""Adopt a new Option object"""
@@ -515,6 +535,25 @@ def reset(self):
515535
"""Set all options to their default values"""
516536
for _option in self.items():
517537
_option.reset()
538+
self.init_logging()
539+
540+
def init_logging(self):
541+
_file = self["LOGGING_CONFIG"]
542+
if _file and os.path.isfile(_file):
543+
try:
544+
import logging
545+
_logging = logging
546+
except ImportError, msg:
547+
raise instance.TrackerError, \
548+
'Python logging module unavailable: %s' % msg
549+
_logging.fileConfig(_file)
550+
else:
551+
_logging = rlog.BasicLogging()
552+
_file = self["LOGGING_FILENAME"]
553+
if _file:
554+
_logging.setFile(_file)
555+
_logging.setLevel(self["LOGGING_LEVEL"] or "ERROR")
556+
self.logging = _logging
518557

519558
# option and section locators (used in option access methods)
520559

@@ -546,6 +585,7 @@ def load_ini(self, tracker_home):
546585
self.TRACKER_HOME = tracker_home
547586
for _option in self.items():
548587
_option.load_ini(_config)
588+
self.init_logging()
549589

550590
def load_pyconfig(self, tracker_home):
551591
"""Set options from config.py file in given tracker_home directory"""
@@ -566,6 +606,7 @@ def load_pyconfig(self, tracker_home):
566606
self.TRACKER_HOME = tracker_home
567607
for _option in self.items():
568608
_option.load_pyconfig(_config)
609+
self.init_logging()
569610
# backward compatibility:
570611
# SMTP login parameters were specified as a tuple in old style configs
571612
# convert them to new plain string options

0 commit comments

Comments
 (0)