Logging file option added

darcs-hash:20071130065953-86b55-53bb8b799504cc5cde5eed96dec9cca46b81d2e5.gz
This commit is contained in:
David Rousselie
2007-11-30 07:59:53 +01:00
parent f0c80d7966
commit b5bdd4c3e0
2 changed files with 17 additions and 3 deletions

View File

@@ -23,4 +23,4 @@ pid_file: /var/run/jabber/jcl.pid
#motd: "Message of the day" #motd: "Message of the day"
welcome_message: "Welcome to JCL" welcome_message: "Welcome to JCL"
admins: admin1@domain.com, admin2@domain.com admins: admin1@domain.com, admin2@domain.com
log_file: /var/log/jabber/jcl.log

View File

@@ -48,6 +48,8 @@ class JCLRunner(object):
self.language = "en" self.language = "en"
self.db_url = "sqlite:///var/spool/jabber/jcl.db" self.db_url = "sqlite:///var/spool/jabber/jcl.db"
self.pid_file = "/var/run/jabber/jcl.pid" self.pid_file = "/var/run/jabber/jcl.pid"
self.log_stdout = False
self.log_file = None
self.options = [("c:", "config-file=", None, self.options = [("c:", "config-file=", None,
" FILE\t\t\t\tConfiguration file to use", " FILE\t\t\t\tConfiguration file to use",
lambda arg: self.set_attr("config_file", arg)), lambda arg: self.set_attr("config_file", arg)),
@@ -75,11 +77,16 @@ class JCLRunner(object):
("d", "debug", None, ("d", "debug", None,
"\t\t\t\t\tEnable debug traces", "\t\t\t\t\tEnable debug traces",
lambda arg: self.set_attr("debug", True)), lambda arg: self.set_attr("debug", True)),
("o", "log-stdout", None,
"\t\t\t\t\tLog on stdout",
lambda arg: self.set_attr("log_stdout", True)),
("f", "log-file", "component",
"\t\t\t\t\tLog in file",
lambda arg: self.set_attr("log_file", arg)),
("h", "help", None, ("h", "help", None,
"\t\t\t\t\tThis help", "\t\t\t\t\tThis help",
lambda arg: self.print_help())] lambda arg: self.print_help())]
self.logger = logging.getLogger() self.logger = logging.getLogger()
self.logger.addHandler(logging.StreamHandler())
self.__debug = False self.__debug = False
def set_attr(self, attr, value): def set_attr(self, attr, value):
@@ -125,7 +132,8 @@ class JCLRunner(object):
set_func(config_property) set_func(config_property)
def configure(self): def configure(self):
"""Apply configuration from command line and configuration file. """
Apply configuration from command line and configuration file.
command line arguments override configuration file properties. command line arguments override configuration file properties.
""" """
shortopts = "" shortopts = ""
@@ -146,6 +154,12 @@ class JCLRunner(object):
self.logger.debug("Debug activated") self.logger.debug("Debug activated")
self.__apply_configfile(commandline_args, cleanopts) self.__apply_configfile(commandline_args, cleanopts)
self.__apply_commandline_args(commandline_args, cleanopts) self.__apply_commandline_args(commandline_args, cleanopts)
if self.log_stdout:
print "Logging to stdout"
self.logger.addHandler(logging.StreamHandler())
if self.log_file is not None:
print "Logging to file " + self.log_file
self.logger.addHandler(logging.FileHandler(self.log_file))
def _get_help(self): def _get_help(self):
help = self.component_name + " v" + self.component_version + " help:\n" help = self.component_name + " v" + self.component_version + " help:\n"