From 8b0e68d9db9905b68ab5f3bcad910bceb47bc4d6 Mon Sep 17 00:00:00 2001 From: kakwa Date: Wed, 6 Jul 2016 21:54:08 +0200 Subject: [PATCH] implementing debug mode in console --- ldapcherry/__init__.py | 12 +++++++++--- scripts/ldapcherryd | 10 ++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index 1b53dbf..1c5bee2 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -260,7 +260,7 @@ class LdapCherry(object): # set log level cherrypy.log.access_log.setLevel(level) - def _set_error_log(self, config, level): + def _set_error_log(self, config, level, debug=False): """ Configure error logs """ error_handler = self._get_param( @@ -305,6 +305,12 @@ class LdapCherry(object): # set log level cherrypy.log.error_log.setLevel(level) + if debug: + handler = logging.StreamHandler(sys.stderr) + handler.setLevel(logging.DEBUG) + cherrypy.log.error_log.addHandler(handler) + cherrypy.log.error_log.setLevel(logging.DEBUG) + def _auth(self, user, password): """ authenticate a user @str user: login of the user @@ -360,7 +366,7 @@ class LdapCherry(object): ): self.temp[t] = self.temp_lookup.get_template(t) - def reload(self, config=None): + def reload(self, config=None, debug=False): """ load/reload configuration @dict: configuration of ldapcherry """ @@ -379,7 +385,7 @@ class LdapCherry(object): # configure access log self._set_access_log(config, level) # configure error log - self._set_error_log(config, level) + self._set_error_log(config, level, debug) # load template files self._load_templates(config) diff --git a/scripts/ldapcherryd b/scripts/ldapcherryd index 003f1be..1547caf 100755 --- a/scripts/ldapcherryd +++ b/scripts/ldapcherryd @@ -17,8 +17,8 @@ from ldapcherry import LdapCherry def start(configfile=None, daemonize=False, environment=None, - fastcgi=False, scgi=False, pidfile=None, imports=None, - cgi=False): + fastcgi=False, scgi=False, pidfile=None, + cgi=False, debug=False): """Subscribe all engine plugins and start the engine.""" sys.path = [''] + sys.path @@ -47,7 +47,7 @@ def start(configfile=None, daemonize=False, environment=None, instance = LdapCherry() app = cherrypy.tree.mount(instance, '/', configfile) cherrypy.config.update(configfile) - instance.reload(app.config) + instance.reload(app.config, debug) engine = cherrypy.engine @@ -123,6 +123,8 @@ if __name__ == '__main__': help="store the process id in the given file") p.add_option('-P', '--Path', action="append", dest='Path', help="add the given paths to sys.path") + p.add_option('-D', '--debug', action="store_true", dest='debug', + help="debug to stderr in foreground") options, args = p.parse_args() if options.Path: @@ -139,4 +141,4 @@ if __name__ == '__main__': start(options.config, options.daemonize, options.environment, options.fastcgi, options.scgi, - options.pidfile, options.cgi) + options.pidfile, options.cgi, options.debug)