[tor-commits] [ooni-probe/master] Feature/show logs (#691)
art at torproject.org
art at torproject.org
Fri Jan 13 12:39:58 UTC 2017
commit acad7172bc5112bac4ba6dbcc1db5f79338914b0
Author: Arturo Filastò <arturo at filasto.net>
Date: Wed Nov 30 19:52:00 2016 +0000
Feature/show logs (#691)
* Add support for obtaining logs from the web interface
---
ooni/ui/web/server.py | 19 +++++++++++++++++++
ooni/utils/log.py | 2 ++
2 files changed, 21 insertions(+)
diff --git a/ooni/ui/web/server.py b/ooni/ui/web/server.py
index 40c03e2..188612f 100644
--- a/ooni/ui/web/server.py
+++ b/ooni/ui/web/server.py
@@ -7,6 +7,7 @@ import string
import random
from functools import wraps
from random import SystemRandom
+from glob import glob
from twisted.internet import defer, task, reactor
from twisted.python import usage
@@ -605,6 +606,24 @@ class WebUIAPI(object):
raise WebUIError(404, "Could not find measurement with this idx")
return self.render_json(r, request)
+ @app.route('/api/logs',
+ methods=["GET"])
+ @xsrf_protect(check=True)
+ @requires_true(attrs=['_is_initialized'])
+ def api_get_logs(self, request):
+ with open(log.oonilogger.log_filepath) as input_file:
+ log_data = input_file.read()
+ logs = {
+ 'latest': log_data,
+ 'older': []
+ }
+ for log_filepath in glob(log.oonilogger.log_filepath + ".*"):
+ with open(log_filepath) as input_file:
+ log_data = input_file.read()
+ logs['older'].append(log_data)
+ logs['older'].reverse()
+ return self.render_json(logs, request)
+
@app.route('/client/', branch=True)
@xsrf_protect(check=False)
def static(self, request):
diff --git a/ooni/utils/log.py b/ooni/utils/log.py
index 42eb9ed..251e160 100644
--- a/ooni/utils/log.py
+++ b/ooni/utils/log.py
@@ -164,6 +164,8 @@ class OONILogger(object):
log_folder = config.running_path
logfile = os.path.join(log_folder, "ooniprobe.log")
+ self.log_filepath = logfile
+
mkdir_p(log_folder)
log_filename = os.path.basename(logfile)
More information about the tor-commits
mailing list