[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 ...
随机推荐
- Double Vision (Unity 5.0)
Double Vision (Unity 5.0): 根据 http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter03.html ...
- 安卓开发--scrollview
package com.cnn.scrollviewdemo01; import android.R.integer; import android.annotation.SuppressLint; ...
- IHttpHandler的学习(0)
本片文章转自网络 问题1:什么是HttpHandler?(Handler:处理者:那就是对Http请求的处理拉) 问题2:什么是HttpModule? 问题3:什么时候应该使用HttpHandler什 ...
- IHttpHandler的学习(1)
IHttpHandler的那些事 今晚看了一晚上的IHttpHAndler的知识, 在自定义了Httphandler后,在配置webconfig里配置也是个技术活,什么集成模式,什么asp管道什么的: ...
- js parseFloat 精度问题
<script type="text/javascript"> //parseFloat function actionoftext(){var price = 10. ...
- T_SQL 字符串函数
字符串函数用于处理列中的数据值,通常属于字符型的数据类型. 1.ASCLL(character),将具体字符转换为相应的整数(ASCII)代码,结果为正数. 例:select ASCII('A'), ...
- [Codeforces 816A]Karen and Morning
题目大意:给你一个时间(hh:mm),求最少经过多少分钟才能使这个时间变成回文. 解题思路:模拟,先判断0的情况,然后每过1分钟判断一次即可. C++ Code: #include<cstdio ...
- PHP -Casbin: 支持 ACL、RBAC、ABAC 多种模型的 PHP 权限管理框架
PHP-Casbin 是一个用 PHP 语言打造的轻量级开源访问控制框架( https://github.com/php-casbin... ),目前在 GitHub 开源.PHP-Casbin 采用 ...
- Python学习笔记(3)--数据结构之列表list
Python的数据结构有三种:列表.元组和字典 列表(list) 定义:list是处理一组有序项目的数据结构,是可变的数据结构. 初始化:[], [1, 3, 7], ['a', 'c'], [1, ...
- 二 MapReduce 各阶段流程分析
如果想要将问题变得清晰.精准和优雅, 需要关注 MapReduce 作业所需要的系统资源,尤其是集群内部网络资源使用情况. MR 可以运行在共享集群上处理 TB 级 甚至 PB 级的数据.同时,改作业 ...