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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. 【Python】【Web.py】详细解读Python的web.py框架下的application.py模块

    详细解读Python的web.py框架下的application.py模块   这篇文章主要介绍了Python的web.py框架下的application.py模块,作者深入分析了web.py的源码, ...

  4. Python的DEBUG LOG

    一直在嵌入式行业,熟悉嵌入式的朋友都很了解嵌入式设备上DEBUG的麻烦,特别是一些缺乏断电工具和没有UI界面的设备.久而久之,开发一个新东西,首先就是要先搞定DEBUG手段.最近写了几个测试的pyth ...

  5. Python开发【第一篇】Python基础之自定义模块和内置模块

    为什么要有模块,将代码归类.模块,用一砣代码实现了某个功能的代码集合. Python中叫模块,其他语言叫类库. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代 ...

  6. python基础系列教程——Python的安装与测试:python的IDE工具PyDev和pycharm,anaconda

    ---恢复内容开始--- python基础系列教程——Python的安装与测试:python的IDE工具PyDev和pycharm,anaconda 从头开启python的开发环境搭建.安装比较简单, ...

  7. 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 ...

  8. 孤荷凌寒自学python第四十五天Python初学基础基本结束的下阶段预安装准备

     孤荷凌寒自学python第四十五天Python初学基础基本结束的下阶段预安装准备 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 今天本来应当继续学习Python的数据库操作,但根据过去我自 ...

  9. PYTHON 100days学习笔记007-1:python数据类型补充(1)

    目录 day007:python数据类型补充(1) 1.数字Number 1.1 Python 数字类型转换 1.2 Python 数字运算 1.3 数学函数 1.4 随机数函数 1.5 三角函数 1 ...

随机推荐

  1. poj_2352树状数组

    因为y已经排好序了,用x坐标建立一维树状数组 #include<iostream> #include<cstdio> #include<cstring> using ...

  2. 查看suse系统版本

    cat /etc/*-release OR lsb_release -d

  3. DC、CDC及CDC的各个子类

      设备描述表是一个包含设备信息的结构体(物理设备如显示器.打印机),MFC中关于图像操作都需要DC来完成.HDC是Windows的一种数据类型,是设备描述句柄:CDC是MFC封装的Windows 设 ...

  4. Intellij使用"easyexplore"

    刚开始接触Intellij,里面有很多东西还不太会用,平时在eclipse里面用的很方便的easyexplore能帮助快速打开文件目录,Intellij中本身就有这样的功能,只是默认没有开启,需要我们 ...

  5. VS2013+PTVS,python编码问题

    1.调试,input('中文'),乱码2.调试,print('中文'),正常3.不调试,input('中文'),正常4.不调试,print('中文'),正常 页面编码方式已经加了"# -- ...

  6. CUDA学习之从CPU架构说起

    最近要学习GPU编程,就去英伟达官网下载CUDA, 遇到的第一个问题就是架构的选择 所以我学习的CUDA的第一步是从学习认识CPU架构开始的,x86-64简称x64,是64位版的x86指令集,向前兼容 ...

  7. AIX系统谨慎使用reboot命令

    在客户一次停机维护中,发现了这个问题. 环境是ORACLE 10G RAC for AIX6,使用了HACMP管理共享磁盘. 在停机维护时间段内需要重启主机,当关闭了数据库和CLUSTER后,节点1使 ...

  8. NodeJS学习笔记 进阶 (9)express+cookie-parser:签名机制深入剖析(ok)

    个人总结:这篇文章讲解了express框架种cookie的使用,需要引用cookie-parser这个包.读完这篇文章需要10分钟. 摘选自网络 文章导读 cookie-parser是Express的 ...

  9. eBay起诉指控亚马逊利用非法手段挖走其卖家

    [摘要]eBay在诉状中称,亚马逊的代表滥用eBay的内部电子邮件系统联系卖家,这违反了市场政策. 腾讯科技讯 10月18日消息,据外媒报道,拍卖网站eBay对亚马逊提起诉讼,指控这家美国零售巨头利用 ...

  10. caioj 1072 动态规划入门(二维一边推5:最长公共子序列 LCSS加强版)

    在51nod刷到过同样的题,直接秒杀 见https://blog.csdn.net/qq_34416123/article/details/81697683 #include<cstdio> ...