diff --git a/aiokeydb/utils/logs.py b/aiokeydb/utils/logs.py index 07ca720..c07fd9d 100644 --- a/aiokeydb/utils/logs.py +++ b/aiokeydb/utils/logs.py @@ -1,4 +1,6 @@ -from lazyops.utils.logs import Logger, get_logger, STATUS_COLOR, COLORED_MESSAGE_MAP, FALLBACK_STATUS_COLOR +from lazyops.utils.logs import Logger, get_logger + +# , STATUS_COLOR, COLORED_MESSAGE_MAP, FALLBACK_STATUS_COLOR class ColorMap: @@ -15,63 +17,64 @@ class ColorMap: -class CustomizeLogger: - - @classmethod - def worker_logger_formatter(cls, record: dict) -> str: - """ - Formats the log message for the worker. - """ - extra = '' - if record['extra'].get('job_id') and record['extra'].get('queue_name') and record['extra'].get('kind'): - status = record['extra'].get('status') - color = STATUS_COLOR.get(status, FALLBACK_STATUS_COLOR) - kind_color = STATUS_COLOR.get(record.get('extra', {}).get('kind'), FALLBACK_STATUS_COLOR) - if not record['extra'].get('worker_name'): - record['extra']['worker_name'] = '' - extra = f'<{kind_color}>' + '{extra[kind]}:' - extra += '{extra[worker_name]}:{extra[queue_name]}:' - extra += '{extra[job_id]}' - if status: - extra += f':<{color}>' + '{extra[status]}' - extra += ': ' - - elif record['extra'].get('kind') and record['extra'].get('queue_name'): - if not record['extra'].get('worker_name'): - record['extra']['worker_name'] = '' - kind_color = STATUS_COLOR.get(record.get('extra', {}).get('kind'), FALLBACK_STATUS_COLOR) - extra = f'<{kind_color}>' + '{extra[kind]}:' - extra += '{extra[worker_name]}:{extra[queue_name]:<18} ' +# class CustomizeLogger: + +# @classmethod +# def worker_logger_formatter(cls, record: dict) -> str: +# """ +# Formats the log message for the worker. +# """ +# extra = '' +# if record['extra'].get('job_id') and record['extra'].get('queue_name') and record['extra'].get('kind'): +# status = record['extra'].get('status') +# color = STATUS_COLOR.get(status, FALLBACK_STATUS_COLOR) +# kind_color = STATUS_COLOR.get(record.get('extra', {}).get('kind'), FALLBACK_STATUS_COLOR) +# if not record['extra'].get('worker_name'): +# record['extra']['worker_name'] = '' +# extra = f'<{kind_color}>' + '{extra[kind]}:' +# extra += '{extra[worker_name]}:{extra[queue_name]}:' +# extra += '{extra[job_id]}' +# if status: +# extra += f':<{color}>' + '{extra[status]}' +# extra += ': ' + +# elif record['extra'].get('kind') and record['extra'].get('queue_name'): +# if not record['extra'].get('worker_name'): +# record['extra']['worker_name'] = '' +# kind_color = STATUS_COLOR.get(record.get('extra', {}).get('kind'), FALLBACK_STATUS_COLOR) +# extra = f'<{kind_color}>' + '{extra[kind]}:' +# extra += '{extra[worker_name]}:{extra[queue_name]:<18} ' - return extra +# return extra - @classmethod - def logger_formatter(cls, record: dict) -> str: - """ - To add a custom format for a module, add another `elif` clause with code to determine `extra` and `level`. +# @classmethod +# def logger_formatter(cls, record: dict) -> str: +# """ +# To add a custom format for a module, add another `elif` clause with code to determine `extra` and `level`. - From that module and all submodules, call logger with `logger.bind(foo='bar').info(msg)`. - Then you can access it with `record['extra'].get('foo')`. - """ - extra = '{name}:{function}: ' +# From that module and all submodules, call logger with `logger.bind(foo='bar').info(msg)`. +# Then you can access it with `record['extra'].get('foo')`. +# """ +# extra = '{name}:{function}: ' - if record.get('extra'): - if record['extra'].get('request_id'): - extra = '{name}:{function}:request_id: {extra[request_id]} ' +# if record.get('extra'): +# if record['extra'].get('request_id'): +# extra = '{name}:{function}:request_id: {extra[request_id]} ' - elif (record['extra'].get('queue_name') or record['extra'].get('worker_name')) and record['extra'].get('kind'): - extra = cls.worker_logger_formatter(record) +# elif (record['extra'].get('queue_name') or record['extra'].get('worker_name')) and record['extra'].get('kind'): +# extra = cls.worker_logger_formatter(record) - if 'result=tensor([' not in str(record['message']): - return "{level: <8} {time:YYYY-MM-DD HH:mm:ss.SSS}: "\ - + extra + "{message}\n" +# if 'result=tensor([' not in str(record['message']): +# return "{level: <8} {time:YYYY-MM-DD HH:mm:ss.SSS}: "\ +# + extra + "{message}\n" - msg = str(record['message'])[:100].replace('{', '(').replace('}', ')') - return "{level: <8} {time:YYYY-MM-DD HH:mm:ss.SSS}: "\ - + extra + "" + msg + f"{STATUS_COLOR['reset']}\n" +# msg = str(record['message'])[:100].replace('{', '(').replace('}', ')') +# return "{level: <8} {time:YYYY-MM-DD HH:mm:ss.SSS}: "\ +# + extra + "" + msg + f"{STATUS_COLOR['reset']}\n" logger: Logger = get_logger( - format = CustomizeLogger.logger_formatter, + __name__, + # format = CustomizeLogger.logger_formatter, ) diff --git a/aiokeydb/version.py b/aiokeydb/version.py index a0966db..ca8ac50 100644 --- a/aiokeydb/version.py +++ b/aiokeydb/version.py @@ -1 +1 @@ -VERSION = '0.2.0rc9' \ No newline at end of file +VERSION = '0.2.1' \ No newline at end of file