aboutsummaryrefslogtreecommitdiff
path: root/helpers.py
diff options
context:
space:
mode:
authorFranoosh <uinarf@autistici.org>2025-07-25 17:13:38 +0200
committerFranoosh <uinarf@autistici.org>2025-10-15 14:33:59 +0200
commit68bd1bd052a7cd6438b92cb1059ef5e58b8d022c (patch)
tree5a7eab3022a7593bd3d9dbdcc99a1590ab0fc3bc /helpers.py
downloadZeroMQ_Video_Streaming-68bd1bd052a7cd6438b92cb1059ef5e58b8d022c.tar.gz
ZeroMQ_Video_Streaming-68bd1bd052a7cd6438b92cb1059ef5e58b8d022c.tar.bz2
ZeroMQ_Video_Streaming-68bd1bd052a7cd6438b92cb1059ef5e58b8d022c.zip
Initial commit. Proof of concept message passing between client <-> router <-> worker with rudimentary caching
Diffstat (limited to 'helpers.py')
-rw-r--r--helpers.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/helpers.py b/helpers.py
new file mode 100644
index 0000000..409a253
--- /dev/null
+++ b/helpers.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+"""
+Helper functions for zmq video messaging.
+"""
+
+__author__ = "Franoosh Corporation"
+
+
+import logging
+
+
+class CustomLoggingFormatter(logging.Formatter):
+ """Custom logging formatter"""
+ debug_fmt = 'DEBUG: %(filename)s:%(lineno)d %(asctime)s %(message)s'
+ info_fmt = 'INFO: %(asctime)s %(message)s'
+ warning_fmt = 'WARNING: %(asctime)s %(message)s'
+ error_fmt = 'ERROR: %(asctime)s %(message)s'
+ critical_fmt = 'CRITICAL: %(asctime)s %(message)s'
+
+ def __init__(self):
+ super().__init__(
+ fmt="%(levelno)d: %s(asctime)s %(message)s",
+ datefmt=None,
+ )
+
+ def format(self, record):
+ orig_fmt = self._style._fmt
+ if record.levelno == logging.DEBUG:
+ self._style._fmt = CustomLoggingFormatter.debug_fmt
+ elif record.levelno == logging.INFO:
+ self._style._fmt = CustomLoggingFormatter.info_fmt
+ elif record.levelno == logging.WARNING:
+ self._style._fmt = CustomLoggingFormatter.warning_fmt
+ elif record.levelno == logging.ERROR:
+ self._style._fmt = CustomLoggingFormatter.error_fmt
+ elif record.levelno == logging.CRITICAL:
+ self._style._fmt = CustomLoggingFormatter.critical_fmt
+
+ result = logging.Formatter.format(self, record)
+ self._style._fmt = orig_fmt
+
+ return result
+