logging_config.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. "general": {
  15. "level": "INFO",
  16. "handlers": ["console", "general"],
  17. "propagate": True,
  18. "qualname": "general.debug",
  19. },
  20. "modbus_connector": {
  21. "level": "INFO",
  22. "handlers": ["console", "modbus_connector"],
  23. "propagate": True,
  24. "qualname": "modbus_connector.debug",
  25. },
  26. "tcp_connector": {
  27. "level": "INFO",
  28. "handlers": ["console", "tcp_connector"],
  29. "propagate": True,
  30. "qualname": "tcp_connector.debug",
  31. },
  32. "sm140_converter": {
  33. "level": "DEBUG",
  34. "handlers": ["console", "sm140_converter"],
  35. "propagate": True,
  36. "qualname": "sm140_converter.debug",
  37. },
  38. "wxt536_converter": {
  39. "level": "DEBUG",
  40. "handlers": ["console", "wxt536_converter"],
  41. "propagate": True,
  42. "qualname": "wxt536_converter.debug",
  43. },
  44. "adcp_converter": {
  45. "level": "DEBUG",
  46. "handlers": ["console", "adcp_converter"],
  47. "propagate": True,
  48. "qualname": "adcp_converter.debug",
  49. },
  50. "cec21_converter": {
  51. "level": "DEBUG",
  52. "handlers": ["console", "cec21_converter"],
  53. "propagate": True,
  54. "qualname": "cec21_converter.debug",
  55. },
  56. "td266_converter": {
  57. "level": "DEBUG",
  58. "handlers": ["console", "td266_converter"],
  59. "propagate": True,
  60. "qualname": "td266_converter.debug",
  61. },
  62. "modbus_converter": {
  63. "level": "DEBUG",
  64. "handlers": ["console", "modbus_converter"],
  65. "propagate": True,
  66. "qualname": "modbus_converter.debug",
  67. },
  68. },
  69. handlers={
  70. # 数据采集程序控制台输出handler
  71. "console": {
  72. "class": "logging.StreamHandler",
  73. "formatter": "generic",
  74. "stream": sys.stdout,
  75. },
  76. "general": {
  77. 'class': 'logging.handlers.RotatingFileHandler',
  78. 'filename': 'log/general/general.log',
  79. 'maxBytes': 10 * 1024 * 1024,
  80. 'delay': True,
  81. "formatter": "generic",
  82. "backupCount": 20,
  83. "encoding": "utf-8"
  84. },
  85. "modbus_connector": {
  86. 'class': 'logging.handlers.RotatingFileHandler',
  87. 'filename': 'log/modbus_connector/modbus_connector.log',
  88. 'maxBytes': 10 * 1024 * 1024,
  89. 'delay': True,
  90. "formatter": "generic",
  91. "backupCount": 20,
  92. "encoding": "utf-8"
  93. },
  94. "tcp_connector": {
  95. 'class': 'logging.handlers.RotatingFileHandler',
  96. 'filename': 'log/tcp_connector/tcp_connector.log',
  97. 'maxBytes': 10 * 1024 * 1024,
  98. 'delay': True,
  99. "formatter": "generic",
  100. "backupCount": 20,
  101. "encoding": "utf-8"
  102. },
  103. "sm140_converter": {
  104. 'class': 'logging.handlers.RotatingFileHandler',
  105. 'filename': 'log/sm140_converter/sm140_converter.log',
  106. 'maxBytes': 10 * 1024 * 1024,
  107. 'delay': True,
  108. "formatter": "generic",
  109. "backupCount": 20,
  110. "encoding": "utf-8"
  111. },
  112. "wxt536_converter": {
  113. 'class': 'logging.handlers.RotatingFileHandler',
  114. 'filename': 'log/wxt536_converter/wxt536_converter.log',
  115. 'maxBytes': 10 * 1024 * 1024,
  116. 'delay': True,
  117. "formatter": "generic",
  118. "backupCount": 20,
  119. "encoding": "utf-8"
  120. },
  121. "adcp_converter": {
  122. 'class': 'logging.handlers.RotatingFileHandler',
  123. 'filename': 'log/adcp_converter/adcp_converter.log',
  124. 'maxBytes': 10 * 1024 * 1024,
  125. 'delay': True,
  126. "formatter": "generic",
  127. "backupCount": 20,
  128. "encoding": "utf-8"
  129. },
  130. "cec21_converter": {
  131. 'class': 'logging.handlers.RotatingFileHandler',
  132. 'filename': 'log/cec21_converter/cec21_converter.log',
  133. 'maxBytes': 10 * 1024 * 1024,
  134. 'delay': True,
  135. "formatter": "generic",
  136. "backupCount": 20,
  137. "encoding": "utf-8"
  138. },
  139. "td266_converter": {
  140. 'class': 'logging.handlers.RotatingFileHandler',
  141. 'filename': 'log/td266_converter/td266_converter.log',
  142. 'maxBytes': 10 * 1024 * 1024,
  143. 'delay': True,
  144. "formatter": "generic",
  145. "backupCount": 20,
  146. "encoding": "utf-8"
  147. },
  148. "modbus_converter": {
  149. 'class': 'logging.handlers.RotatingFileHandler',
  150. 'filename': 'log/modbus_converter/modbus_converter.log',
  151. 'maxBytes': 10 * 1024 * 1024,
  152. 'delay': True,
  153. "formatter": "generic",
  154. "backupCount": 20,
  155. "encoding": "utf-8"
  156. },
  157. },
  158. formatters={
  159. # 自定义文件格式化器
  160. "generic": {
  161. "format": "%(asctime)s {%(process)d(%(thread)d)} [%(filename)s:%(lineno)d] [%(levelname)s] %(message)s",
  162. "datefmt": "[%Y-%m-%d %H:%M:%S]",
  163. "class": "logging.Formatter",
  164. },
  165. },
  166. )
  167. general = logging.getLogger("general")
  168. modbus_connector = logging.getLogger("modbus_connector")
  169. tcp_connector = logging.getLogger("tcp_connector")
  170. sm140_converter = logging.getLogger("sm140_converter")
  171. wxt536_converter = logging.getLogger("wxt536_converter")
  172. adcp_converter = logging.getLogger("adcp_converter")
  173. cec21_converter = logging.getLogger("cec21_converter")
  174. td266_converter = logging.getLogger("td266_converter")
  175. modbus_converter = logging.getLogger("modbus_converter")