fixed logging in background daemon

This commit is contained in:
Joel Klimont 2021-10-01 13:37:56 +02:00
parent 3eab71aaf5
commit d1a86d2c0e
4 changed files with 44 additions and 19 deletions

View file

@ -34,7 +34,7 @@ fpm -s python --python-bin python3 --python-pip pip3 --python-package-name-prefi
-d "python3-pigpio" \ -d "python3-pigpio" \
-d "python3-numpy" \ -d "python3-numpy" \
-d "ffmpeg" \ -d "ffmpeg" \
-v 0.2.3-1 -t deb setup.py -v 0.2.4-0 -t deb setup.py
# --deb-changelog changelog \ # --deb-changelog changelog \
# --deb-upstream-changelog changelog \ # --deb-upstream-changelog changelog \

View file

@ -1,21 +1,38 @@
import os import os
import socket
import threading import threading
import time import time
import systemd.daemon import systemd.daemon
import LogstashLogging
from LogstashLogging import logstash_logger try:
from threading import Thread from compLib.LogstashLogging import Logging
import logging except Exception as e:
import socket import logging
class Logger():
def __init__(self):
self.logger = logging.Logger('compApi background')
def get_logger(self):
return self.logger
Logging = Logger()
print(f"Could not import compLib.LogstashLogging: {str(e)}")
Logging.get_logger().error(f"Could not import compLib.LogstashLogging: {str(e)}")
print("after basic imports")
RUN_IP_CHECK = False RUN_IP_CHECK = False
try: try:
from compLib.Display import Display from compLib.Display import Display
from compLib.Spi import Spi from compLib.Spi import Spi
except Exception as e: except Exception as e:
logstash_logger.warning(f"Could not import display or spi for ip output {str(e)}") print(f"Could not import display or spi for ip output {str(e)}")
Logging.get_logger().warning(f"Could not import display or spi for ip output {str(e)}")
print(f"After display and Spi import")
__run = """raspivid -t 0 -b 5000000 -w 1280 -h 720 -fps 30 -n -o - | gst-launch-1.0 fdsrc ! video/x-h264,width=1280,height=720,framerate=30/1,noise-reduction=1,profile=high,stream-format=byte-stream ! h264parse ! queue ! flvmux streamable=true ! rtmpsink location=\"rtmp://localhost/live/stream\"""" __run = """raspivid -t 0 -b 5000000 -w 1280 -h 720 -fps 30 -n -o - | gst-launch-1.0 fdsrc ! video/x-h264,width=1280,height=720,framerate=30/1,noise-reduction=1,profile=high,stream-format=byte-stream ! h264parse ! queue ! flvmux streamable=true ! rtmpsink location=\"rtmp://localhost/live/stream\""""
@ -38,7 +55,8 @@ def get_ip():
def write_ip_to_screen(): def write_ip_to_screen():
while not os.getenv("IP_OUTPUT", "false") == "false": while not os.getenv("IP_OUTPUT", "false") == "false":
ip = str(get_ip()) ip = str(get_ip())
logstash_logger.info(f"writing {ip} to display") print(f"writing {ip} to display")
Logging.get_logger().info(f"writing {ip} to display")
Display.write(1, ip) Display.write(1, ip)
time.sleep(60) time.sleep(60)
@ -47,28 +65,35 @@ if __name__ == '__main__':
try: try:
systemd.daemon.notify(systemd.daemon.Notification.READY) systemd.daemon.notify(systemd.daemon.Notification.READY)
except: except:
logstash_logger.warning("Warning, old systemd version detected") Logging.get_logger().warning("Warning, old systemd version detected")
systemd.daemon.notify('READY=1') systemd.daemon.notify('READY=1')
logstash_logger.info("starting ip output") print("starting ip output")
Logging.get_logger().info("starting ip output")
ip_output = None ip_output = None
if RUN_IP_CHECK and IP_OUTPUT: if RUN_IP_CHECK and IP_OUTPUT:
try: try:
Spi.disable_health_check() Spi.disable_health_check()
ip_output = threading.Thread(target=write_ip_to_screen) ip_output = threading.Thread(target=write_ip_to_screen)
ip_output.start() ip_output.start()
logstash_logger.info("starting ip output - DONE") print("starting ip output - DONE")
Logging.get_logger().info("starting ip output - DONE")
except Exception as e: except Exception as e:
logstash_logger.error(f"could not start ip output -> {str(e)}") print(f"could not start ip output -> {str(e)}")
Logging.get_logger().error(f"could not start ip output -> {str(e)}")
if STREAM_RASPI: if STREAM_RASPI:
logstash_logger.info("starting gstreamer background process") print("starting gstreamer background process")
Logging.get_logger().info("starting gstreamer background process")
os.system(__run) os.system(__run)
logstash_logger.error("gstreamer stopped...") print("gstreamer stopped...")
Logging.get_logger().error("gstreamer stopped...")
else: else:
logstash_logger.info("not starting gstreamer background process and only checking for battery") print("not starting gstreamer background process and only checking for battery")
Logging.get_logger().info("not starting gstreamer background process and only checking for battery")
if ip_output is not None: if ip_output is not None:
ip_output.join() ip_output.join()
else: else:
logstash_logger.info("ip display output failed to initialize.. sleeping for a day, good night") print("ip display output failed to initialize.. sleeping for a day, good night")
time.sleep(60*60*24) Logging.get_logger().info("ip display output failed to initialize.. sleeping for a day, good night")
time.sleep(60 * 60 * 24)

View file

@ -1,4 +1,4 @@
__version__ = "0.2.3-1" __version__ = "0.2.4-0"
import importlib import importlib
import compLib.LogstashLogging import compLib.LogstashLogging

View file

@ -12,7 +12,7 @@ else:
setuptools.setup( setuptools.setup(
name="complib", name="complib",
version="0.2.3-1", version="0.2.4-0",
author="F-WuTs", author="F-WuTs",
author_email="--", author_email="--",
description="", description="",