aboutsummaryrefslogtreecommitdiff
path: root/scripts/redis_logger.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/redis_logger.py')
-rw-r--r--scripts/redis_logger.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/scripts/redis_logger.py b/scripts/redis_logger.py
index 97ffe26..76b8ba6 100644
--- a/scripts/redis_logger.py
+++ b/scripts/redis_logger.py
@@ -31,3 +31,16 @@ class RedisLogger(logging.Handler):
self.redisconnection.rpush(
self.messages_list_name(), self.format(record))
self.redisconnection.expire(self.messages_list_name(), self.expiry)
+
+def setup_redis_logger(rconn: Redis,
+ jobid: uuid.UUID,
+ job_messagelist: str,
+ expiry: int = 86400) -> RedisLogger:
+ """Setup a default RedisLogger logger."""
+ formatter = logging.Formatter(
+ "%(asctime)s - %(name)s - %(levelname)s: %(message)s")
+ # job_messagelist = f"{str(args.jobid)}:log-messages"
+ rconn.hset(name=str(jobid), key="log-messagelist", value=job_messagelist)
+ redislogger = RedisLogger(rconn, jobid, expiry=expiry)
+ redislogger.setFormatter(formatter)
+ return redislogger