33 lines
861 B
Python
33 lines
861 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
import os
|
|
|
|
print("=== 测试输出 ===", flush=True)
|
|
print("Python版本:", sys.version, flush=True)
|
|
print("当前工作目录:", os.getcwd(), flush=True)
|
|
print("stdout编码:", sys.stdout.encoding, flush=True)
|
|
print("stderr编码:", sys.stderr.encoding, flush=True)
|
|
|
|
import logging
|
|
|
|
# 配置日志
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
|
handlers=[logging.StreamHandler(sys.stdout)]
|
|
)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger.info("这是一条测试日志")
|
|
logger.warning("这是一条警告日志")
|
|
|
|
print("测试完成!", flush=True)
|
|
|
|
# 写入文件测试
|
|
with open("test_log.txt", "w", encoding="utf-8") as f:
|
|
f.write("测试文件写入\n")
|
|
f.write(f"时间: {os.times()}\n")
|
|
|
|
print("文件写入完成", flush=True) |