1-1 基础练习
最后更新于:2022-04-02 07:44:51
~~~
#!/usr/bin/env python
# coding: utf-8
# @Time : 2021/11/10 15:01
# @Author : YD
# @Email : dinhe_1985@126.com
# @File : log-1.py
# @Software: PyCharm
# @Blog : www.noteshare.cn
import logging
# 日志默认级别调整
logging.basicConfig(level=logging.DEBUG)
logging.info('This is info log')
logging.error('This is error log')
# 日志写入文件及写入模式设置
logging.basicConfig(filename='demo.log', filemode='w', level=logging.DEBUG)
# 日志变量传递
logging.basicConfig(filename='demo.log', filemode='w', level=logging.DEBUG)
name = '丁贺'
age = 30
logging.error('姓名 {} , 年龄 {} '.format(name,age))
# 日志输入内容加入时间
logging.basicConfig(format="%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s")
name = '丁贺'
age = 30
logging.error('姓名 {} , 年龄 {} '.format(name, age))
# 自定义时间格式
logging.basicConfig(format="%(asctime)s|%(levelname)s|%(filename)s:%(lineno)s|%(message)s",
datefmt="%Y-%m-%d %H:%M:%S")
name = '丁贺'
age = 30
logging.error('姓名 {} , 年龄 {} '.format(name, age))
~~~
';