Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logger page #15

Merged
merged 5 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
filename="smarthome.log",
filename=os.path.join(config.CONFIG_DIRECTORY, "smarthome.log"),
filemode='w')
logging.getLogger().addHandler(logging.StreamHandler())
logging.getLogger("urllib3").setLevel(logging.WARNING)
Expand Down
25 changes: 23 additions & 2 deletions smarthome.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import json
import hashlib

from time import time
from time import time, sleep
from werkzeug.utils import secure_filename
from werkzeug.middleware.proxy_fix import ProxyFix
from domoticz import getDomoticzDevices, queryDomoticz, saveJson
from helpers import logger, get_settings, save_settings, remove_user, check_token, get_token, random_string, get_device, get_devices, generateToken, generateCsrfToken, csrfProtect
from reportstate import ReportState
from flask import Flask, redirect, request, url_for, render_template, send_from_directory, jsonify, session, flash
from flask import Flask, redirect, request, url_for, render_template, send_from_directory, jsonify, session, flash, Response
from secrets import compare_digest

app = Flask(__name__)
Expand Down Expand Up @@ -397,6 +397,27 @@ def settings():
devices = devices,
_csrf_token=session['_csrf_token']
)

@app.route('/logging')
@flask_login.login_required
def logging():
settings=get_settings()

return render_template('logging.html',
user = flask_login.current_user.id,
settings = settings)

@app.route("/log_stream", methods=["GET"])
@flask_login.login_required
def stream():
"""returns logging information"""
def generate():
filename = os.path.join(config.CONFIG_DIRECTORY, "smarthome.log")
with open(filename) as f:
while True:
yield f.read()
sleep(1)
return Response(generate(), mimetype='text/plain')

@app.route('/devices')
@flask_login.login_required
Expand Down
70 changes: 70 additions & 0 deletions templates/logging.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{% include 'head.html' %}

{% include 'header.html' %}

{% include 'sidebar.html' %}

<style>
.logging_window{
display: block;
padding: 9.5px;
font-size: 16px;
line-height: 1.42857143;
color: #333;
word-break: break-all;
word-wrap: break-word;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
width: 100%;
height: 400px;
margin: auto;
}
</style>
<main id="main" class="main">

<div class="pagetitle">
<h1>Logs</h1>
<nav>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ url_for('dashboard') }}">Dashboard</a></li>
<li class="breadcrumb-item active">Logs</li>
</ol>
</nav>
</div><!-- End Page Title -->

<section class="section">
<div class="row dashboard">

<!-- Left side columns -->
<div class="col-lg-12">
<div class="row">

<div class="col-12">
<div class="card recent-sales overflow-auto">

<div class="card-body">
<h5 class="card-title">Logs <span>| {{ user }}</span></h5>
<iframe class="logging_window"
src="{{ url_for('stream')}}">
</iframe>
</div>
</div>

</div>
</div><!-- End Left side columns -->

<!-- Right side columns -->
<div class="col-lg-12">



</div><!-- End Right side columns -->
</div>
</div>
</div>
</section>

</main><!-- End #main -->

{% include 'footer.html' %}
12 changes: 9 additions & 3 deletions templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
<span>Devices</span>
</a>
</li>
{% if settings['USERS'][user]['admin'] %}
{% if settings['USERS'][user]['admin'] %}
<li class="nav-item">
<a class="nav-link collapsed" href="{{ url_for('settings') }}">
<i class="material-symbols-outlined" style="font-size: 24px">settings</i>
<span>Settings</span>
</a>
</li>
{% endif %}
<li class="nav-item">
<a class="nav-link collapsed" href="{{ url_for('logging') }}">
<i class="material-symbols-outlined" style="font-size: 24px">summarize</i>
<span>Logs</span>
</a>
</li>
{% endif %}

</ul>

</aside><!-- End Sidebar-->
</aside><!-- End Sidebar-->