Toggle VERBOSE at runtime. Just surf to /toggleVerbose. Comes in handy for the ones who don't want to change startup scripts

This commit is contained in:
Bas Stottelaar
2014-05-12 11:45:28 +02:00
parent 9b2594355f
commit 45868bc523
4 changed files with 22 additions and 2 deletions

View File

@@ -101,7 +101,7 @@ def main():
try:
file(headphones.PIDFILE, 'w').write("pid\n")
except IOError, e:
raise SystemExit("Unable to write PID file: %s [%d]" % (e.strerror, e.errno))
raise SystemExit("Unable to write PID file: %s [%d]", e.strerror, e.errno)
else:
logger.warn("Not running in daemon mode. PID file creation disabled.")

View File

@@ -38,7 +38,7 @@ SIGNAL = None
SYS_PLATFORM = None
SYS_ENCODING = None
QUIET = True
QUIET = False
VERBOSE = False
DAEMON = False
CREATEPID = False
@@ -720,6 +720,7 @@ def initialize():
# Start the logger, disable console if needed
logger.initLogger(console=not QUIET, verbose=VERBOSE)
logger.initLogger(console=not QUIET, verbose=False)
if not CACHE_DIR:
# Put the cache dir in the data dir for now

View File

@@ -55,6 +55,17 @@ def initLogger(console=False, verbose=False):
Console logging is only enabled if console is set to True.
"""
# Close and remove old handlers. This is required to reinit the loggers
# at runtime
for handler in logger.handlers[:]:
# Just make sure it is cleaned up.
if isinstance(handler, handlers.RotatingFileHandler):
handler.close()
elif isinstance(handler, logging.StreamHandler):
handler.flush()
logger.removeHandler(handler)
# Configure the logger to accept all messages
logger.propagate = False
logger.setLevel(logging.DEBUG if verbose else logging.INFO)

View File

@@ -736,6 +736,14 @@ class WebInterface(object):
raise cherrypy.HTTPRedirect("logs")
clearLogs.exposed = True
def toggleVerbose(self):
headphones.VERBOSE = not headphones.VERBOSE
logger.initLogger(not headphones.QUIET, headphones.VERBOSE)
logger.info("Verbose toggled, set to %s", headphones.VERBOSE)
logger.debug("If you read this message, debug logging is available")
raise cherrypy.HTTPRedirect("logs")
toggleVerbose.exposed = True
def getLog(self,iDisplayStart=0,iDisplayLength=100,iSortCol_0=0,sSortDir_0="desc",sSearch="",**kwargs):
iDisplayStart = int(iDisplayStart)