added option to disable logging

This commit is contained in:
Joel 2021-01-28 14:21:30 +01:00
parent e02b42060b
commit acc91cdd74
No known key found for this signature in database
GPG key ID: BDDDBECD0808290E
3 changed files with 32 additions and 17 deletions

View file

@ -32,7 +32,7 @@ fpm -s python --python-bin python3 --python-pip pip3 --python-package-name-prefi
-d "python-pigpio" \ -d "python-pigpio" \
-d "python3-pigpio" \ -d "python3-pigpio" \
-d "python3-numpy" \ -d "python3-numpy" \
-v 0.0.3-7 -t deb setup.py -v 0.0.3-8 -t deb setup.py
# --deb-changelog changelog \ # --deb-changelog changelog \
# --deb-upstream-changelog changelog \ # --deb-upstream-changelog changelog \

View file

@ -1,10 +1,18 @@
import logging import logging
import os
import sys import sys
import requests import requests
from logstash_async.transport import HttpTransport from logstash_async.transport import HttpTransport
from logstash_async.handler import AsynchronousLogstashHandler from logstash_async.handler import AsynchronousLogstashHandler
EXTENSIVE_LOGGING = os.getenv("EXTENSIVE_LOGGING", "True")
if EXTENSIVE_LOGGING == "True":
EXTENSIVE_LOGGING = True
else:
EXTENSIVE_LOGGING = False
host = 'logstash.robo4you.at' host = 'logstash.robo4you.at'
port = 443 port = 443
@ -52,6 +60,7 @@ class StreamToLogger(object):
asynchronousLogstashHandler.flush() asynchronousLogstashHandler.flush()
if EXTENSIVE_LOGGING:
try: try:
r = requests.get(f"https://{host}:{port}") r = requests.get(f"https://{host}:{port}")
if r.status_code == 401: if r.status_code == 401:
@ -68,7 +77,8 @@ try:
except requests.exceptions.ConnectionError as identifier: except requests.exceptions.ConnectionError as identifier:
print(f"Could not connect to {host}!") print(f"Could not connect to {host}!")
print(f"Error loading logger was -> {identifier}") print(f"Error loading logger was -> {identifier}")
pass else:
print("Extensive logging is disabled! No logs will be sent over network...")
class Logging(object): class Logging(object):

View file

@ -1,7 +1,9 @@
import os import os
import threading
import cv2 import cv2
import logging
import threading
import LogstashLogging
from flask import Flask, Response from flask import Flask, Response
RTMP_SERVER = os.getenv("RTMP_SERVER", "rtmp://localhost/live/stream") RTMP_SERVER = os.getenv("RTMP_SERVER", "rtmp://localhost/live/stream")
@ -49,6 +51,7 @@ class __Streaming:
# self.__camera_stream = cv2.VideoCapture(0) # self.__camera_stream = cv2.VideoCapture(0)
self.__newest_frame = None self.__newest_frame = None
self.__lock = threading.Lock() self.__lock = threading.Lock()
logging.info("Initialized vision")
def get_frame(self): def get_frame(self):
""" """
@ -101,6 +104,7 @@ Streaming = None
if BUILDING_DOCS == "false": if BUILDING_DOCS == "false":
# instantiate private class __Streaming # instantiate private class __Streaming
Streaming = __Streaming() Streaming = __Streaming()
logging.info("created instance of streaming class")
@app.route("/live") @app.route("/live")
@ -130,6 +134,7 @@ def __start_flask():
:return: :return:
""" """
logging.info("starting flask server")
app.run(host="0.0.0.0", port=9898, debug=True, threaded=True, use_reloader=False) app.run(host="0.0.0.0", port=9898, debug=True, threaded=True, use_reloader=False)