]> jspc29.x-matter.uni-frankfurt.de Git - mvd_epics.git/commitdiff
DASH: New --logfile parameter
authorPhilipp Klaus <philipp.klaus@gmail.com>
Mon, 25 Sep 2017 06:26:43 +0000 (14:26 +0800)
committerPhilipp Klaus <philipp.klaus@gmail.com>
Mon, 25 Sep 2017 06:26:43 +0000 (14:26 +0800)
python_suite/dashboard/dashboard.py
python_suite/dashboard/requirements.txt

index 9e2f25ce63ec183abdf4536f488bfc1ea184457f..51cb8318970b9080adb8f708024aae65ceaae86d 100755 (executable)
@@ -4,8 +4,10 @@ import json, threading, time, copy, math
 
 import simplejson
 import epics
-from bottle import Bottle, route, run, static_file, redirect, abort, response, HTTPResponse, server_names
+from bottle import Bottle, run, static_file, redirect, abort, response, HTTPResponse, server_names
 from bottle import jinja2_view as view
+from requestlogger import WSGILogger, ApacheFormatter
+from logging.handlers import TimedRotatingFileHandler
 
 CONFIG = None
 PVS = {}
@@ -244,7 +246,7 @@ def static_content(path):
 # ---------- main() function - managing CLI arg parsing / startup ----------
 
 def main():
-    global CONFIG, PVS, HISTORY
+    global CONFIG, PVS, HISTORY, app
 
     import argparse, sys
     parser = argparse.ArgumentParser()
@@ -257,6 +259,8 @@ def main():
     parser.add_argument('--server', default='wsgiref',
           help='Server engine to run the application. Valid choices: ' + ', '.join(server_names) + '. '
                'The default is wsgiref (try bjoern or paste for high performance and read https://goo.gl/SmPFZb).')
+    parser.add_argument('--logfile',
+          help='If provided, the server will log requests to this file in "Apache format".')
     parser.add_argument('--debug', action='store_true',
           help='Set the debug mode of the web server.')
     args = parser.parse_args()
@@ -280,6 +284,10 @@ def main():
         CONFIG['PV_lookup'][pv['name']] = i
         HISTORY[pv['name']] = []
 
-    run(host=args.host, port=args.port, debug=args.debug, server=args.server)
+    if args.logfile:
+        handlers = [ TimedRotatingFileHandler(args.logfile, when='W0', interval=1) , ]
+        app = WSGILogger(app, handlers, ApacheFormatter())
+
+    run(app, host=args.host, port=args.port, debug=args.debug, server=args.server)
 
 if __name__ == "__main__": main()
index 39a718d899a6eea8f93b8abe2089f758db9d8dd0..b811a52c92d820961756676ff4ea6ce48e347971 100644 (file)
@@ -2,3 +2,4 @@ bottle
 jinja2
 pyepics
 simplejson
+wsgi-request-logger