feat:更改配置文件

This commit is contained in:
2025-10-20 15:43:03 +08:00
parent 132fbb13b7
commit 398ad56933
3 changed files with 9 additions and 34 deletions

View File

@@ -10,8 +10,11 @@ ES_PASSWORD = "19940822Cxx"
BLOG_INDEX = "blog" BLOG_INDEX = "blog"
# 注意Python的elasticsearch的版本要和服务器的一致 # 注意Python的elasticsearch的版本要和服务器的一致
try:
es = Elasticsearch(ES_HOST, http_auth=(ES_USER, ES_PASSWORD)) es = Elasticsearch(ES_HOST, http_auth=(ES_USER, ES_PASSWORD))
if not es.indices.exists(index=BLOG_INDEX): if not es.indices.exists(index=BLOG_INDEX):
es.indices.create(index=BLOG_INDEX, body=BLOG_MAPPING) es.indices.create(index=BLOG_INDEX, body=BLOG_MAPPING)
logger.info(f"Elastic索引 {BLOG_INDEX} 创建成功") logger.info(f"Elastic索引 {BLOG_INDEX} 创建成功")
except Exception as e:
logger.error(f"elastic异常: {str(e)}")

View File

@@ -3,18 +3,13 @@ import sys
from fluent import sender from fluent import sender
from loguru import logger from loguru import logger
from pathlib import Path
from config.setting import settings from config.setting import settings
FLUENTD_HOST = 'host.docker.internal' FLUENTD_HOST = settings.FLUENTD_HOST
FLUENTD_PORT = 24224 FLUENTD_PORT = 24224
TOPIC_TAG = 'blog-service' TOPIC_TAG = 'blog-service'
# 日志目录
LOG_DIR = Path(__file__).parent.parent / "logs"
LOG_DIR.mkdir(exist_ok=True)
# 日志级别 # 日志级别
LOG_LEVEL = settings.LOG_LEVEL.upper() LOG_LEVEL = settings.LOG_LEVEL.upper()
@@ -88,30 +83,6 @@ logger.add(
diagnose=True # 显示诊断信息 diagnose=True # 显示诊断信息
) )
# # 添加文件处理器 - 常规日志
# logger.add(
# sink=LOG_DIR / "app.log",
# level="INFO",
# format=FILE_FORMAT,
# rotation="10 MB", # 日志文件大小达到10MB时自动分割
# retention="7 days", # 保留7天的日志
# compression="zip", # 归档时压缩为zip
# enqueue=True, # 异步写入
# serialize=False, # 不使用JSON格式
# )
#
# # 添加文件处理器 - 错误日志
# logger.add(
# sink=LOG_DIR / "error.log",
# level="ERROR",
# format=FILE_FORMAT,
# rotation="10 MB",
# retention="30 days",
# compression="zip",
# enqueue=True,
# serialize=False,
# )
atexit.register(fluent_sender.close) atexit.register(fluent_sender.close)
# 导出配置好的logger # 导出配置好的logger

View File

@@ -7,6 +7,7 @@ class Settings(BaseSettings):
DB_HOST: str DB_HOST: str
DB_PASSWORD: str DB_PASSWORD: str
ES_HOST: str ES_HOST: str
FLUENTD_HOST: str
class Config: class Config:
env_file = ".env" # 指定.env文件路径 env_file = ".env" # 指定.env文件路径