diff options
author | Frederick Muriuki Muriithi | 2024-01-15 06:07:05 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-01-15 06:07:05 +0300 |
commit | 8fe991c20f27702ee34ffcdd0cbc96e411db8c90 (patch) | |
tree | 509c0d1a00bf96bc3308802765e5ae63cfeb123c /scripts/redis_logger.py | |
parent | f89c08c392182b669d058a4c21feffde64b15ebb (diff) | |
download | gn-uploader-8fe991c20f27702ee34ffcdd0cbc96e411db8c90.tar.gz |
Extract common structure into separate modules.
Diffstat (limited to 'scripts/redis_logger.py')
-rw-r--r-- | scripts/redis_logger.py | 13 |
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 |