-
Notifications
You must be signed in to change notification settings - Fork 0
/
weblog.py
38 lines (33 loc) · 893 Bytes
/
weblog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import flask
import os
# serves logs/mail.log in Browser
app = flask.Flask(__name__)
@app.route('/')
def index():
return """
<html>
<head>
<script>
function getLog() {
fetch('/get_log')
.then(response => response.text())
.then(data => {
document.getElementById('log-content').textContent = data;
});
}
getLog(); // immediately after page load
setInterval(getLog, 10000); // every 10 seconds
</script>
</head>
<body>
<pre id="log-content"></pre>
</body>
</html>
"""
@app.route('/get_log')
def get_log():
if not os.path.exists('logs/mail.log'):
return 'No log file'
with open('logs/mail.log') as f:
return f.read()
app.run(debug=True, host='0.0.0.0', port=5001)