Files
alert-contract-expiring-hr/scripts/util/logging_setup.py
taojianmin 06c053d7d7 v1.1.0: 实现核心业务逻辑(扫描/任务书/派发/状态机)
新增(scripts/ 分层完整实现):
- scripts/util/{constants,date_util,runtime_paths,logging_setup}.py
- scripts/db/{connection,seed_data,repository}.py(SQLite + 5 张表 + 50 份样例合同)
- scripts/service/{scanner,task_generator,dispatcher,html_renderer}.py
- scripts/cli/app.py(argparse 子命令)
- scripts/templates/task.html.j2(Jinja2 渲染,无 jinja2 时降级到 str.replace)
- examples/{contracts_sample,performance_sample}.csv(本地样例数据)

修改:
- scripts/main.py:argparse + jiangchang_skill_core 降级
- SKILL.md:version 1.0.1 → 1.1.0
- CHANGELOG.md:加 v1.1.0 条目
- .env.example:加 DB_PATH / HTML_OUTPUT_DIR / JIANGCHANG_DATA_DIR

本地验证(9 个 CLI 命令全部 exit code = 0):
- health / version / config-path / init-db:基础 4 命令
- scan-expiring-contracts --thresholds 90,60,30:42 份可续聘 → 红 10 / 橙 10 / 黄 10,生成 30 任务
- render-html:写 output/<task_id>.html(4.9 KB)
- generate-renewal-task:单份合同任务书生成
- mark-contract-renewed:状态机更新 + 关闭 open alerts
- dispatch-task-notice:按单位/月份派发 payload(dry-run 模式)

业务规则(AI 续聘建议本地版,规则顺序判断):
1. 师德 < 60 → non_renew
2. 近 3 年考核有不合格(< 60)→ observe
3. 全部 >= 80 且逐年上升 → renew
4. 其他 → observe

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-14 14:17:43 +08:00

54 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""logging 配置:降级到 stderr,避免污染 stdout(stdout 留给结构化输出如 JSON)。
优先用 jiangchang_skill_core 提供的 logging;本地无该包时降级到 stderr。
"""
from __future__ import annotations
import logging
import sys
from util.constants import LOG_LOGGER_NAME, SKILL_SLUG, SKILL_VERSION
_configured = False
def setup_skill_logging() -> logging.Logger:
"""初始化 skill logger(幂等)。"""
global _configured
logger = logging.getLogger(LOG_LOGGER_NAME)
if _configured:
return logger
# 优先用宿主提供的 skill logger 配置
try:
from jiangchang_skill_core.logging_config import setup_skill_logging as _host_setup
_host_setup(SKILL_SLUG, LOG_LOGGER_NAME)
_configured = True
return logging.getLogger(LOG_LOGGER_NAME)
except ImportError:
pass
# 本地降级:基础 stderr handler,UTF-8 safe
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(
logging.Formatter(
fmt=f"%(asctime)s [{SKILL_SLUG}] %(levelname)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
)
logger.setLevel(logging.INFO)
logger.addHandler(handler)
logger.propagate = False
_configured = True
logger.info("logging initialized (local fallback) v%s", SKILL_VERSION)
return logger
def get_skill_logger() -> logging.Logger:
"""获取 skill logger(不会重复 setup)。"""
if not _configured:
return setup_skill_logging()
return logging.getLogger(LOG_LOGGER_NAME)