config.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Time : 2024/10/15 15:13
  5. @File : config.py
  6. @Desc :
  7. """
  8. import logging
  9. import os
  10. from logging.handlers import TimedRotatingFileHandler, QueueListener,QueueHandler
  11. from multiprocessing import Queue
  12. FILE_PATH = os.path.join(os.path.dirname(__file__), "data")
  13. LOG_PATH = os.path.join(os.path.dirname(__file__), "log")
  14. def get_logger(file ="log"):
  15. logfile = os.path.join(LOG_PATH, file+".log")
  16. logger = logging.getLogger(logfile)
  17. logger.propagate = True
  18. logger.setLevel(logging.INFO)
  19. sh = logging.StreamHandler()
  20. formatter = logging.Formatter('%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s - %(message)s')
  21. sh.setFormatter(formatter)
  22. logger.addHandler(sh)
  23. if file:
  24. fh = TimedRotatingFileHandler(logfile, when="midnight", backupCount=10, encoding="utf-8")
  25. #fh = logging.FileHandler(logfile)
  26. fh.setFormatter(formatter)
  27. logger.addHandler(fh)
  28. logger.addHandler(sh)
  29. # log_queue=Queue(-1)
  30. # qh = QueueHandler(log_queue)
  31. # qh.setFormatter(formatter)
  32. # logger.addHandler(qh)
  33. # ql=QueueListener(log_queue, fh, sh, respect_handler_level=True)
  34. # ql.start()
  35. return logger
  36. START = 'start'
  37. END = 'done'
  38. HANGUP = 'hang'
  39. TRANSFER = 'transfer'
  40. CONTINUE = 'normal'
  41. EMPTY = 'empty'
  42. MAX_TIMES_ANSWER = '播放次数超限'
  43. FAQ = 'faq'
  44. PURSUE = 'pursue'
  45. UNK = 'others'
  46. GENERATED = 'generated'
  47. FIXED = 'fixed'
  48. MOUDLES = {
  49. "10001": {
  50. "faq": {
  51. "content": ["未知"],
  52. "speech_id": "mainContent",
  53. "speech_type": "mainType",
  54. "speech_interrupt": "mainInterrupt"
  55. }
  56. }
  57. }
  58. # 异常类型
  59. INTENT_ERROR = '意图分类服务异常'
  60. def main():
  61. logger = get_logger()
  62. logger.info("hello")
  63. print(FILE_PATH)
  64. if __name__ == "__main__":
  65. main()