logging_config.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. """
  2. @File : log_config.py
  3. @Author: lee
  4. @Date : 2022/7/13/0013 11:08:55
  5. @Desc :
  6. """
  7. import logging
  8. import sys
  9. LOGGING_CONFIG = dict(
  10. version=1,
  11. disable_existing_loggers=False,
  12. loggers={
  13. # 新曾自定义日志,用于数据采集程序
  14. "console": {
  15. "level": "DEBUG",
  16. "handlers": ["console", "connector_file"],
  17. "propagate": True,
  18. "qualname": "console.debug",
  19. },
  20. "sm140_file": {
  21. "level": "DEBUG",
  22. "handlers": ["console", "sm140_file"],
  23. "propagate": True,
  24. "qualname": "sm140.debug",
  25. },
  26. "wxt536_file": {
  27. "level": "DEBUG",
  28. "handlers": ["console", "wxt536_file"],
  29. "propagate": True,
  30. "qualname": "wxt536.debug",
  31. },
  32. "adcp_file": {
  33. "level": "DEBUG",
  34. "handlers": ["console", "adcp_file"],
  35. "propagate": True,
  36. "qualname": "adcp.debug",
  37. },
  38. "dandian_file": {
  39. "level": "DEBUG",
  40. "handlers": ["console", "dandian_file"],
  41. "propagate": True,
  42. "qualname": "dandian.debug",
  43. },
  44. "td266_file": {
  45. "level": "DEBUG",
  46. "handlers": ["console", "td266_file"],
  47. "propagate": True,
  48. "qualname": "td266.debug",
  49. },
  50. "shuizhi_file": {
  51. "level": "DEBUG",
  52. "handlers": ["console", "shuizhi_file"],
  53. "propagate": True,
  54. "qualname": "shuizhi.debug",
  55. },
  56. },
  57. handlers={
  58. # 数据采集程序控制台输出handler
  59. "console": {
  60. "class": "logging.StreamHandler",
  61. "formatter": "generic",
  62. "stream": sys.stdout,
  63. },
  64. "connector_file": {
  65. 'class': 'logging.handlers.RotatingFileHandler',
  66. 'filename': 'log/connector_log/connector_file.log',
  67. 'maxBytes': 10 * 1024 * 1024,
  68. 'delay': True,
  69. "formatter": "generic",
  70. "backupCount": 20,
  71. "encoding": "utf-8"
  72. },
  73. "sm140_file": {
  74. 'class': 'logging.handlers.RotatingFileHandler',
  75. 'filename': 'log/sm140_log/sm140_file.log',
  76. 'maxBytes': 10 * 1024 * 1024,
  77. 'delay': True,
  78. "formatter": "generic",
  79. "backupCount": 20,
  80. "encoding": "utf-8"
  81. },
  82. "wxt536_file": {
  83. 'class': 'logging.handlers.RotatingFileHandler',
  84. 'filename': 'log/wxt536_log/wxt536_log.log',
  85. 'maxBytes': 10 * 1024 * 1024,
  86. 'delay': True,
  87. "formatter": "generic",
  88. "backupCount": 20,
  89. "encoding": "utf-8"
  90. },
  91. "adcp_file": {
  92. 'class': 'logging.handlers.RotatingFileHandler',
  93. 'filename': 'log/adcp_log/adcp_log.log',
  94. 'maxBytes': 10 * 1024 * 1024,
  95. 'delay': True,
  96. "formatter": "generic",
  97. "backupCount": 20,
  98. "encoding": "utf-8"
  99. },
  100. "dandian_file": {
  101. 'class': 'logging.handlers.RotatingFileHandler',
  102. 'filename': 'log/dandian_log/dandian_log.log',
  103. 'maxBytes': 10 * 1024 * 1024,
  104. 'delay': True,
  105. "formatter": "generic",
  106. "backupCount": 20,
  107. "encoding": "utf-8"
  108. },
  109. "td266_file": {
  110. 'class': 'logging.handlers.RotatingFileHandler',
  111. 'filename': 'log/td266_log/td266_log.log',
  112. 'maxBytes': 10 * 1024 * 1024,
  113. 'delay': True,
  114. "formatter": "generic",
  115. "backupCount": 20,
  116. "encoding": "utf-8"
  117. },
  118. "shuizhi_file": {
  119. 'class': 'logging.handlers.RotatingFileHandler',
  120. 'filename': 'log/shuizhi_log/shuizhi_log.log',
  121. 'maxBytes': 10 * 1024 * 1024,
  122. 'delay': True,
  123. "formatter": "generic",
  124. "backupCount": 20,
  125. "encoding": "utf-8"
  126. },
  127. },
  128. formatters={
  129. # 自定义文件格式化器
  130. "generic": {
  131. "format": "%(asctime)s [%(filename)s:%(lineno)d] [%(levelname)s] %(message)s",
  132. "datefmt": "[%Y-%m-%d %H:%M:%S]",
  133. "class": "logging.Formatter",
  134. },
  135. },
  136. )
  137. logger = logging.getLogger("console")
  138. sm140_file_logger = logging.getLogger("sm140_file")
  139. wxt536_file_logger = logging.getLogger("wxt536_file")
  140. adcp_file_logger = logging.getLogger("adcp_file")
  141. dandian_file_logger = logging.getLogger("dandian_file")
  142. td266_file_logger = logging.getLogger("td266_file")
  143. shuizhi_file_logger = logging.getLogger("shuizhi_file")