1 Star 0 Fork 0

Pency/cursor-auto-free

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
logger.py 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
import logging
import os
from datetime import datetime
# Configure logging
log_dir = "logs"
if not os.path.exists(log_dir):
os.makedirs(log_dir)
logging.basicConfig(
filename=os.path.join(log_dir, f"{datetime.now().strftime('%Y-%m-%d')}.log"),
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s",
encoding="utf-8",
)
# 创建控制台处理器
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(logging.Formatter("%(message)s"))
# 将控制台处理器添加到日志记录器
logging.getLogger().addHandler(console_handler)
# 打印日志目录所在路径
logging.info(f"Logger initialized, log directory: {os.path.abspath(log_dir)}")
def main_task():
"""
Main task execution function. Simulates a workflow and handles errors.
"""
try:
logging.info("Starting the main task...")
# Simulated task and error condition
if some_condition():
raise ValueError("Simulated error occurred.")
logging.info("Main task completed successfully.")
except ValueError as ve:
logging.error(f"ValueError occurred: {ve}", exc_info=True)
except Exception as e:
logging.error(f"Unexpected error occurred: {e}", exc_info=True)
finally:
logging.info("Task execution finished.")
def some_condition():
"""
Simulates an error condition. Returns True to trigger an error.
Replace this logic with actual task conditions.
"""
return True
if __name__ == "__main__":
# Application workflow
logging.info("Application started.")
main_task()
logging.info("Application exited.")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pencynobug/cursor-auto-free.git
git@gitee.com:pencynobug/cursor-auto-free.git
pencynobug
cursor-auto-free
cursor-auto-free
main

搜索帮助