1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-22 17:34:21 +01:00

implementing debug mode in console

This commit is contained in:
kakwa 2016-07-06 21:54:08 +02:00
parent 5944b81aed
commit 8b0e68d9db
2 changed files with 15 additions and 7 deletions

View File

@ -260,7 +260,7 @@ class LdapCherry(object):
# set log level # set log level
cherrypy.log.access_log.setLevel(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 """ Configure error logs
""" """
error_handler = self._get_param( error_handler = self._get_param(
@ -305,6 +305,12 @@ class LdapCherry(object):
# set log level # set log level
cherrypy.log.error_log.setLevel(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): def _auth(self, user, password):
""" authenticate a user """ authenticate a user
@str user: login of the user @str user: login of the user
@ -360,7 +366,7 @@ class LdapCherry(object):
): ):
self.temp[t] = self.temp_lookup.get_template(t) self.temp[t] = self.temp_lookup.get_template(t)
def reload(self, config=None): def reload(self, config=None, debug=False):
""" load/reload configuration """ load/reload configuration
@dict: configuration of ldapcherry @dict: configuration of ldapcherry
""" """
@ -379,7 +385,7 @@ class LdapCherry(object):
# configure access log # configure access log
self._set_access_log(config, level) self._set_access_log(config, level)
# configure error log # configure error log
self._set_error_log(config, level) self._set_error_log(config, level, debug)
# load template files # load template files
self._load_templates(config) self._load_templates(config)

View File

@ -17,8 +17,8 @@ from ldapcherry import LdapCherry
def start(configfile=None, daemonize=False, environment=None, def start(configfile=None, daemonize=False, environment=None,
fastcgi=False, scgi=False, pidfile=None, imports=None, fastcgi=False, scgi=False, pidfile=None,
cgi=False): cgi=False, debug=False):
"""Subscribe all engine plugins and start the engine.""" """Subscribe all engine plugins and start the engine."""
sys.path = [''] + sys.path sys.path = [''] + sys.path
@ -47,7 +47,7 @@ def start(configfile=None, daemonize=False, environment=None,
instance = LdapCherry() instance = LdapCherry()
app = cherrypy.tree.mount(instance, '/', configfile) app = cherrypy.tree.mount(instance, '/', configfile)
cherrypy.config.update(configfile) cherrypy.config.update(configfile)
instance.reload(app.config) instance.reload(app.config, debug)
engine = cherrypy.engine engine = cherrypy.engine
@ -123,6 +123,8 @@ if __name__ == '__main__':
help="store the process id in the given file") help="store the process id in the given file")
p.add_option('-P', '--Path', action="append", dest='Path', p.add_option('-P', '--Path', action="append", dest='Path',
help="add the given paths to sys.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() options, args = p.parse_args()
if options.Path: if options.Path:
@ -139,4 +141,4 @@ if __name__ == '__main__':
start(options.config, options.daemonize, start(options.config, options.daemonize,
options.environment, options.fastcgi, options.scgi, options.environment, options.fastcgi, options.scgi,
options.pidfile, options.cgi) options.pidfile, options.cgi, options.debug)