config.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import os
  2. from logging.config import dictConfig
  3. from src.core.datasource import SERVE_HOST, MYSQL_PASSWORD
  4. class BaseConfig(object):
  5. # 数据库的配置
  6. DIALCT = "mysql"
  7. DRITVER = "pymysql"
  8. HOST = SERVE_HOST
  9. PORT = "3306"
  10. USERNAME = "root"
  11. PASSWORD = MYSQL_PASSWORD
  12. DBNAME = 'libra_bot'
  13. SQLALCHEMY_DATABASE_URI = f"{DIALCT}+{DRITVER}://{USERNAME}:{PASSWORD}@{HOST}:{PORT}/{DBNAME}?charset=utf8"
  14. SQLALCHEMY_TRACK_MODIFICATIONS = False # Disable track modifications
  15. SQLALCHEMY_ECHO = False # Optional: Log SQL queries
  16. dictConfig({
  17. "version": 1,
  18. "disable_existing_loggers": True, # 不覆盖默认配置
  19. "formatters": { # 日志输出样式
  20. "default": {
  21. "format": "%(asctime)s - %(module)s.%(lineno)d - %(levelname)s - %(threadName)s: %(message)s"
  22. }
  23. },
  24. "handlers": {
  25. "console": {
  26. "class": "logging.StreamHandler", # 控制台输出
  27. "level": "DEBUG",
  28. "formatter": "default",
  29. },
  30. # "log_file": {
  31. # "class": "logging.handlers.TimedRotatingFileHandler", # 按时间切分日志
  32. # "level": "DEBUG",
  33. # "formatter": "default", # 日志输出样式对应formatters
  34. # "filename": "./logs/flask.log", # 指定log文件目录
  35. # "when": "midnight", # 按天切分,午夜时分创建新文件
  36. # "interval": 1, # 间隔1天
  37. # "backupCount": 10, # 保留10天的日志文件
  38. # "encoding": "utf8", # 文件编码
  39. # },
  40. },
  41. "root": {
  42. "level": "DEBUG", # # handler中的level会覆盖掉这里的level
  43. "handlers": ["console"],
  44. },
  45. }
  46. )