added option to disable logging
This commit is contained in:
parent
e02b42060b
commit
acc91cdd74
3 changed files with 32 additions and 17 deletions
|
@ -32,7 +32,7 @@ fpm -s python --python-bin python3 --python-pip pip3 --python-package-name-prefi
|
|||
-d "python-pigpio" \
|
||||
-d "python3-pigpio" \
|
||||
-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-upstream-changelog changelog \
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
import requests
|
||||
|
||||
from logstash_async.transport import HttpTransport
|
||||
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'
|
||||
port = 443
|
||||
|
||||
|
@ -52,23 +60,25 @@ class StreamToLogger(object):
|
|||
asynchronousLogstashHandler.flush()
|
||||
|
||||
|
||||
try:
|
||||
r = requests.get(f"https://{host}:{port}")
|
||||
if r.status_code == 401:
|
||||
logstash_logger.addHandler(asynchronousLogstashHandler)
|
||||
if EXTENSIVE_LOGGING:
|
||||
try:
|
||||
r = requests.get(f"https://{host}:{port}")
|
||||
if r.status_code == 401:
|
||||
logstash_logger.addHandler(asynchronousLogstashHandler)
|
||||
|
||||
so = StreamToLogger(sys.stdout, logging.INFO)
|
||||
sys.stdout = so
|
||||
so = StreamToLogger(sys.stdout, logging.INFO)
|
||||
sys.stdout = so
|
||||
|
||||
se = StreamToLogger(sys.stderr, logging.ERROR)
|
||||
sys.stderr = se
|
||||
else:
|
||||
print(f"Could not connect to {host} -> ERROR CODE: {r.status_code}!")
|
||||
se = StreamToLogger(sys.stderr, logging.ERROR)
|
||||
sys.stderr = se
|
||||
else:
|
||||
print(f"Could not connect to {host} -> ERROR CODE: {r.status_code}!")
|
||||
|
||||
except requests.exceptions.ConnectionError as identifier:
|
||||
print(f"Could not connect to {host}!")
|
||||
print(f"Error loading logger was -> {identifier}")
|
||||
pass
|
||||
except requests.exceptions.ConnectionError as identifier:
|
||||
print(f"Could not connect to {host}!")
|
||||
print(f"Error loading logger was -> {identifier}")
|
||||
else:
|
||||
print("Extensive logging is disabled! No logs will be sent over network...")
|
||||
|
||||
|
||||
class Logging(object):
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import os
|
||||
import threading
|
||||
|
||||
import cv2
|
||||
import logging
|
||||
import threading
|
||||
import LogstashLogging
|
||||
|
||||
from flask import Flask, Response
|
||||
|
||||
RTMP_SERVER = os.getenv("RTMP_SERVER", "rtmp://localhost/live/stream")
|
||||
|
@ -49,6 +51,7 @@ class __Streaming:
|
|||
# self.__camera_stream = cv2.VideoCapture(0)
|
||||
self.__newest_frame = None
|
||||
self.__lock = threading.Lock()
|
||||
logging.info("Initialized vision")
|
||||
|
||||
def get_frame(self):
|
||||
"""
|
||||
|
@ -101,6 +104,7 @@ Streaming = None
|
|||
if BUILDING_DOCS == "false":
|
||||
# instantiate private class __Streaming
|
||||
Streaming = __Streaming()
|
||||
logging.info("created instance of streaming class")
|
||||
|
||||
|
||||
@app.route("/live")
|
||||
|
@ -130,6 +134,7 @@ def __start_flask():
|
|||
|
||||
:return:
|
||||
"""
|
||||
logging.info("starting flask server")
|
||||
app.run(host="0.0.0.0", port=9898, debug=True, threaded=True, use_reloader=False)
|
||||
|
||||
|
||||
|
|
Reference in a new issue