Python根据系统环境配置日志,Python配置日志 Python logger

 

我们通常在写爬虫的时候,需要配置日志,但是有可能是在windows开发的,但是程序的运行环境可是是在Linux中,这时候我们就需要不停的更换日志的目录了

但是我们可以实现通过判断不同的运行环境,来时间日志的配置

 

例如:

import platform
sysStr = platform.system()
if sysStr =="Windows":
    LOG_FILE_check = 'C:\\log\\wlb\\crawler\\cic.log'
else:
    LOG_FILE_check = '/log/wlb/crawler/cic.log'

# 日志的配置环境
handler = logging.handlers.RotatingFileHandler(LOG_FILE_check, maxBytes=128 * 1024 * 1024,backupCount=10)  # 实例化handler  200M 最多十个文件
fmt = '\n' + '%(asctime)s - %(filename)s:%(lineno)s  - %(message)s'
formatter = logging.Formatter(fmt)  # 实例化formatter
handler.setFormatter(formatter)  # 为handler添加formatter
logger = logging.getLogger('check')  # 获取名为tst的logger
logger.addHandler(handler)  # 为logger添加handler
logger.setLevel(logging.DEBUG)

  

 

转载于:https://www.cnblogs.com/xuchunlin/p/6986323.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值