123456789101112131415161718192021222324252627282930 |
- # update: 2021-1-15-18
- import prettytable as pt
- import logging
- logger = logging.getLogger('log_method')
- def show_logs(tags, args, is_work=True):
- """log格式化"""
- if not is_work:
- return
- if type(args) == dict:
- text = pt.PrettyTable()
- text.field_names = ['参数', '类型', '值']
- text.align = 'l'
- for name, value in args.items():
- too_long = len(str(value)) > 200
- if too_long:
- dots = '..'
- else:
- dots = ''
- text.add_row([name, str(type(value)), str(repr(value))[:200] + dots])
- logger.info(f"{tags}:\n{text}")
- elif type(args) == list:
- lines = f"{tags}:"
- for count, line in enumerate(args):
- lines += f"\n- {count + 1} - {line}"
- logger.info(lines)
- else:
- logger.info(f"{tags}: {args}")
|