[Python] Create a Log for your Python application
Print statements will get you a long way in monitoring the behavior of your application, but logging will get your further. Learn how to implement logging in this lesson to generate INFO, WARNING, ERROR, and DEBUG logs for your application.
import sys
import getopt
import logging # pass in: python3 my_log.py -l info # Get command line options
# short: l:
# long: [log=]
opts, args = getopt.getopt(sys.argv[1:], "l:", ["log="]) print("opts", opts) #[('-l', 'info')]
print("args", args) #[] # default log level
log_level="INFO" for opt, arg in opts: #opt: -l, arg: info
if opt in ("-l", "--log"):
log_level = getattr(logging, arg.upper()) logging.basicConfig(filename="./demo.log", level=log_level, format='%(asctime)s %(levelname)s:%(message)s') for i in range(0, 100):
if i % 5 == 0:
logging.debug('Found a number divisible by 5: {0}'.format(i))
else:
logging.info('At number {0}'.format(i)) logging.warning('Finished sequence')
[Python] Create a Log for your Python application的更多相关文章
- [Python] Create Unique Unordered Collections in Python with Set
A set is an unordered collection with no duplicate items in Python. In this lesson, you will learn h ...
- [Python] Create a minimal website in Python using the Flask Microframework
How to install Flask Use Flask to create a minimal website Build routes in Flask to respond to websi ...
- 【Python】【Web.py】详细解读Python的web.py框架下的application.py模块
详细解读Python的web.py框架下的application.py模块 这篇文章主要介绍了Python的web.py框架下的application.py模块,作者深入分析了web.py的源码, ...
- Python的DEBUG LOG
一直在嵌入式行业,熟悉嵌入式的朋友都很了解嵌入式设备上DEBUG的麻烦,特别是一些缺乏断电工具和没有UI界面的设备.久而久之,开发一个新东西,首先就是要先搞定DEBUG手段.最近写了几个测试的pyth ...
- Python开发【第一篇】Python基础之自定义模块和内置模块
为什么要有模块,将代码归类.模块,用一砣代码实现了某个功能的代码集合. Python中叫模块,其他语言叫类库. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代 ...
- python基础系列教程——Python的安装与测试:python的IDE工具PyDev和pycharm,anaconda
---恢复内容开始--- python基础系列教程——Python的安装与测试:python的IDE工具PyDev和pycharm,anaconda 从头开启python的开发环境搭建.安装比较简单, ...
- Introspection in Python How to spy on your Python objects Guide to Python introspection
Guide to Python introspection https://www.ibm.com/developerworks/library/l-pyint/ Guide to Python in ...
- 孤荷凌寒自学python第四十五天Python初学基础基本结束的下阶段预安装准备
孤荷凌寒自学python第四十五天Python初学基础基本结束的下阶段预安装准备 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天本来应当继续学习Python的数据库操作,但根据过去我自 ...
- PYTHON 100days学习笔记007-1:python数据类型补充(1)
目录 day007:python数据类型补充(1) 1.数字Number 1.1 Python 数字类型转换 1.2 Python 数字运算 1.3 数学函数 1.4 随机数函数 1.5 三角函数 1 ...
随机推荐
- mac鼠标滚动方向自然问题
mac使用鼠标的时候滚轮方向和Windows是相反的.假设不勾选滚动方向自然,那么触摸板使用不爽. 解决的方法: 1.打开http://pilotmoon.com/scrollreverser/,下载 ...
- 获取当前最上层controller
- (UIViewController *)topViewController { UIViewController *resultVC; resultVC = [self _topViewContr ...
- dns-sd._udp.<domain>. 域名发现 本质和MDNS同
DNS Service Discovery is a way of using standard DNS programming interfaces, servers, and packet for ...
- [BZOJ3670] [NOI2014] 动物园 解题报告 (KMP)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3670 Description 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅, ...
- 关于table布局
html-table 宝贝 状态 单价 数量 商品总价 运费 1sdsdf 2 3fffff 4sdfsfsffsdfs 5dsfs 6
- GoldenGate 反向切换步骤
1 事先配置好反向复制链路: 2 停止源端的应用程序; 3 确认源端Capture已捕获所有的Redo信息: GGSCI>info all GGSCI>info ext_app 4 确认源 ...
- Linux安装多功能词典GoldenDict
Linux安装多功能词典GoldenDict 活腿肠 2017.08.01 20:52* 字数 671 阅读 1555评论 0喜欢 2 Goldendict 简介 GoldenDict是一种开源的辞典 ...
- [POI2010]GIL-Guilds(结论题)
题意 给一张无向图,要求你用黑白灰给点染色,且满足对于任意一个黑点,至少有一个白点和他相邻:对于任意一个白点,至少有一个黑点与他相邻,对于任意一个灰点,至少同时有一个黑点和白点和灰点与他相邻,问能否成 ...
- Vector源码学习
安全的可增长数组结构 实现: 1. 内部采用数组的方式. 1.1 添加元素,会每次校验容量是否满足, 扩容规则有两种,1.增加扩容补偿的长度,2.按照现有数组长度翻一倍.容量上限是Integer.MA ...
- Xshell6连接Ubuntu18.04
1.首先在自己windows10电脑上安装了xshell6,安装过程不叙述了 2.打开xshell 3.执行新建命令.打开Xshell软件后找到左上角第一个“文件”菜单并单击,弹出来一个下拉框,点击选 ...