diff options
Diffstat (limited to 'scripts/redis_logger.py')
-rw-r--r-- | scripts/redis_logger.py | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/scripts/redis_logger.py b/scripts/redis_logger.py index 76b8ba6..2ae682b 100644 --- a/scripts/redis_logger.py +++ b/scripts/redis_logger.py @@ -1,46 +1,41 @@ """Utilities to log to redis for our worker scripts.""" -import uuid import logging from redis import Redis class RedisLogger(logging.Handler): """Log out to redis for our worker scripts""" - def __init__(self, # pylint: disable=[too-many-arguments] + def __init__(self,#pylint: disable=[too-many-arguments] rconn: Redis, - jobid: uuid.UUID, + fullyqualifiedjobid: str, + messageslistname: str, level:int = logging.NOTSET, - messagelistname: str = "log-messages", expiry: int = 86400): """Initialise the handler.""" super().__init__(level) self.redisconnection = rconn - self.jobid = jobid - self.messagelistname = messagelistname + self.jobid = fullyqualifiedjobid + self.messageslistname = messageslistname self.expiry = expiry - rconn.hset(name=str(jobid), + rconn.hset(name=fullyqualifiedjobid, key="log-messagelist", - value=self.messages_list_name()) - - def messages_list_name(self): - """Retrieve the fully qualified message-list name""" - return f"{str(self.jobid)}:{self.messagelistname}" + value=messageslistname) def emit(self, record): """Log to the messages list for a given worker.""" - self.redisconnection.rpush( - self.messages_list_name(), self.format(record)) - self.redisconnection.expire(self.messages_list_name(), self.expiry) + self.redisconnection.rpush(self.messageslistname, self.format(record)) + self.redisconnection.expire(self.messageslistname, self.expiry) def setup_redis_logger(rconn: Redis, - jobid: uuid.UUID, + fullyqualifiedjobid: str, 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) + rconn.hset( + name=fullyqualifiedjobid, key="log-messagelist", value=job_messagelist) + redislogger = RedisLogger( + rconn, fullyqualifiedjobid, job_messagelist, expiry=expiry) redislogger.setFormatter(formatter) return redislogger |