You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

log.py 1.3 KiB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. # @Date : 2017-10-14 15:35:17
  3. # @Author : leizi
  4. '''日志模块'''
  5. import os
  6. import logbook
  7. from logbook.more import ColorizedStderrHandler
  8. from functools import wraps
  9. check_path = '.'
  10. LOG_DIR = os.path.join(check_path, 'log')
  11. file_stream = False
  12. if not os.path.exists(LOG_DIR):
  13. os.makedirs(LOG_DIR)
  14. file_stream = True
  15. def get_logger(name='interface_case_run', file_log=file_stream, level=''):
  16. """ get logger Factory function """
  17. logbook.set_datetime_format('local')
  18. ColorizedStderrHandler(bubble=False, level=level).push_thread()
  19. logbook.TimedRotatingFileHandler(
  20. os.path.join(LOG_DIR, '%s.log' % name),
  21. date_format='%Y_%m_%d_%H', bubble=True, encoding='utf-8').push_thread()
  22. return logbook.Logger(name)
  23. LOG = get_logger(file_log=file_stream, level='INFO')
  24. def logger(param):
  25. """ fcuntion from logger meta """
  26. def wrap(function):
  27. """ logger wrapper """
  28. @wraps(function)
  29. def _wrap(*args, **kwargs):
  30. """ wrap tool """
  31. LOG.info("当前模块 {}".format(param))
  32. LOG.info("全部args参数参数信息 , {}".format(str(args)))
  33. LOG.info("全部kwargs参数信息 , {}".format(str(kwargs)))
  34. return function(*args, **kwargs)
  35. return _wrap
  36. return wrap

Introduction

生成接口测试报告

No topics