Skip to content

Commit

Permalink
implementing debug mode in console
Browse files Browse the repository at this point in the history
  • Loading branch information
kakwa committed Jul 6, 2016
1 parent 5944b81 commit 8b0e68d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 9 additions & 3 deletions ldapcherry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _set_access_log(self, config, level):
# 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(
Expand Down Expand Up @@ -305,6 +305,12 @@ def _set_error_log(self, config, level):
# 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
Expand Down Expand Up @@ -360,7 +366,7 @@ def _load_templates(self, config):
):
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
"""
Expand All @@ -379,7 +385,7 @@ def reload(self, config=None):
# 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)
Expand Down
10 changes: 6 additions & 4 deletions scripts/ldapcherryd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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)

0 comments on commit 8b0e68d

Please sign in to comment.