27 lines
641 B
Python
27 lines
641 B
Python
|
from logger import log
|
||
|
|
||
|
def main():
|
||
|
log.info("程序启动")
|
||
|
try:
|
||
|
# 你的代码
|
||
|
log.debug("调试信息: %s", some_var) # type: ignore
|
||
|
except Exception as e:
|
||
|
log.error("操作失败: %s", str(e), exc_info=True)
|
||
|
raise
|
||
|
# 自定义日志器
|
||
|
custom_log = setup_logging(
|
||
|
name="MyModule",
|
||
|
log_dir="custom_logs",
|
||
|
file_level=logging.INFO,
|
||
|
console_level=logging.DEBUG,
|
||
|
max_bytes=5*1024*1024, # 5MB
|
||
|
backup_count=3
|
||
|
)
|
||
|
|
||
|
# 使用示例
|
||
|
custom_log.warning("自定义日志记录")
|
||
|
# 使用示例
|
||
|
custom_log.warning("自定义日志记录")
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|