|
|
@@ -1,3 +1,5 @@
|
|
|
+import logging
|
|
|
+
|
|
|
from aiomysql import create_pool
|
|
|
from aiomysql.cursors import DictCursor
|
|
|
|
|
|
@@ -5,6 +7,9 @@ from app.core.config import GlobalConfigSettings
|
|
|
from app.core.observability import LogService
|
|
|
|
|
|
|
|
|
+logging.basicConfig(level=logging.INFO)
|
|
|
+
|
|
|
+
|
|
|
class DatabaseManager(LogService):
|
|
|
def __init__(self, config: GlobalConfigSettings):
|
|
|
super().__init__(config.aliyun_log)
|
|
|
@@ -33,7 +38,7 @@ class DatabaseManager(LogService):
|
|
|
autocommit=True,
|
|
|
)
|
|
|
self.pools[db_name] = pool
|
|
|
- print(f"DETAIL\t{db_name} MYSQL连接池 created successfully")
|
|
|
+ logging.info(f"{db_name} MYSQL连接池 created successfully")
|
|
|
|
|
|
except Exception as e:
|
|
|
await self.log(
|
|
|
@@ -50,6 +55,7 @@ class DatabaseManager(LogService):
|
|
|
if pool:
|
|
|
pool.close()
|
|
|
await pool.wait_closed()
|
|
|
+ logging.info(f"{name} MYSQL连接池 closed successfully")
|
|
|
|
|
|
async def async_fetch(
|
|
|
self, query, db_name="long_articles", params=None, cursor_type=DictCursor
|