day23-python之日志 re模块
1.logging
import logging #-----------------------------------logging.basicConfig
logging.basicConfig(
level=logging.DEBUG,
filename="logger.log",
filemode="w",
format="%(asctime)s %(filename)s[%(lineno)d] %(message)s" )
#
# logging.debug('hello')
# logging.info('hello')
# logging.warning('warning message')
# logging.error('error message')
# logging.critical('critical message') #-----------------------------------logger
def logger():
logger=logging.getLogger() fh=logging.FileHandler("test_log")
#ch=logging.StreamHandler() fm=logging.Formatter("%(asctime)s %(message)s") fh.setFormatter(fm)
#ch.setFormatter(fm) logger.addHandler(fh)
#logger.addHandler(ch)
logger.setLevel("DEBUG") return logger
# #----------------------
logger=logger() #
# logger.debug("debug")
# logger.info("info")
# logger.warning("warning")
# logger.error("error")
# logger.critical("critical")
#--------------------------------------------------
import logging
#
logger=logging.getLogger() logger1 = logging.getLogger('mylogger')
logger1.setLevel(logging.DEBUG) logger2 = logging.getLogger('mylogger')
logger2.setLevel(logging.WARNING) fh=logging.FileHandler("test_log-new")
ch=logging.StreamHandler() logger.addHandler(ch)
logger.addHandler(fh) logger1.addHandler(fh)
logger1.addHandler(ch) logger2.addHandler(fh)
logger2.addHandler(ch) # logger.debug('logger debug message')
# logger.info('logger info message')
# logger.warning('logger warning message')
# logger.error('logger error message')
# logger.critical('logger critical message') # logger1.debug('logger1 debug message')
# logger1.info('logger1 info message')
# logger1.warning('logger1 warning message')
# logger1.error('logger1 error message')
# logger1.critical('logger1 critical message') logger2.debug('logger2 debug message')
logger2.info('logger2 info message')
logger2.warning('logger2 warning message')
logger2.error('logger2 error message')
logger2.critical('logger2 critical message')
2.configparser
import configparser
# config = configparser.ConfigParser() #config={}
# #
# #
# #
# #
# config["DEFAULT"] = {'ServerAliveInterval': '45',
# 'Compression': 'yes',
# 'CompressionLevel': '9'}
# #
# #
# #
# config['bitbucket.org'] = {}
# config['bitbucket.org']['User'] = 'hg'
# #
# config['topsecret.server.com'] = {}
# topsecret = config['topsecret.server.com']
# topsecret['Host Port'] = '50022' # mutates the parser
# topsecret['ForwardX11'] = 'no' # same here
# #
# #
# #
# with open('example.ini', 'w') as f:
# config.write(f)
#------------------------------------------------------增删改查、
import configparser
#
config = configparser.ConfigParser()
#---------------------------------------------查
# print(config.sections()) #[]
config.read('example.ini')
# #
# print(config.sections()) #['bitbucket.org', 'topsecret.server.com']
# print('bitbucket.org' in config)# False
#
# print(config['bitbucket.org']['User']) # hg
#
# print(config['DEFAULT']['Compression']) #yes
#
# print(config['topsecret.server.com']['ForwardX11']) #no
# for key in config['bitbucket.org']:
# print(key)
#
#
# print(config.options('bitbucket.org'))#['user', 'serveraliveinterval', 'compression', 'compressionlevel', 'forwardx11']
# print(config.items('bitbucket.org')) #[('serveraliveinterval', '45'), ('compression', 'yes'), ('compressionlevel', '9'), ('forwardx11', 'yes'), ('user', 'hg')]
#
# print(config.get('bitbucket.org','compression'))#yes
#
#
# #---------------------------------------------删,改,增(config.write(open('i.cfg', "w")))
#
#
config.add_section('yuan')
config.set('yuan','k1','')
#
config.remove_section('topsecret.server.com')
config.remove_option('bitbucket.org','user')
# #
#
config.write(open('i.cfg', "w"))
3.md5加密
# import hashlib # obj=hashlib.md5()
#
# obj.update("admin".encode("utf8"))
# print(obj.hexdigest()) #21232f297a57a5a743894a0e4a801fc3 # obj.update("adminroot".encode("utf8"))
# print(obj.hexdigest())# 4b3626865dc6d5cfe1c60b855e68634a
# 4b3626865dc6d5cfe1c60b855e68634a
day23-python之日志 re模块的更多相关文章
- python中日志logging模块的性能及多进程详解
python中日志logging模块的性能及多进程详解 使用Python来写后台任务时,时常需要使用输出日志来记录程序运行的状态,并在发生错误时将错误的详细信息保存下来,以别调试和分析.Python的 ...
- [ Python入门教程 ] Python中日志记录模块logging使用实例
python中的logging模块用于记录日志.用户可以根据程序实现需要自定义日志输出位置.日志级别以及日志格式. 将日志内容输出到屏幕 一个最简单的logging模块使用样例,直接打印显示日志内容到 ...
- python 的日志logging模块
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message')logging.info('This is info messag ...
- python的日志logging模块性能以及多进程
写在前面: 日志是记录操作的一种好方式.但是日志,基本都是基于文件的,也就是要写到磁盘上的.这时候,磁盘将会成为一个性能瓶颈.对于普通的服务器硬盘(机械磁盘,非固态硬盘),python日志的性能瓶颈是 ...
- python 的日志logging模块学习
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...
- Python之日志 logging模块
关于logging模块的日志功能 典型的日志记录的步骤是这样的: 创建logger 创建handler 定义formatter 给handler添加formatter 给logger添加handler ...
- Python中日志logging模块
# coding:utf-8 import logging import os import time class Logger(object): def __init__(self): # 创建一个 ...
- python标准日志模块logging及日志系统设计
最近写一个爬虫系统,需要用到python的日志记录模块,于是便学习了一下. python的标准库里的日志系统从Python2.3开始支持.只要import logging这个模块即可使用.如果你想开发 ...
- python标准日志模块logging的使用方法
参考地址 最近写一个爬虫系统,需要用到python的日志记录模块,于是便学习了一下.python的标准库里的日志系统从Python2.3开始支持.只要import logging这个模块即可使用.如果 ...
- 【python】日志系统
来源: http://blog.csdn.net/wykgf/article/details/11576721 http://www.jb51.net/article/42626.htm http:/ ...
随机推荐
- asp.net web 开发中配置web.config
一.配置数据库连接字符串 <connectionStrings> <add name="CaoLPractise" connectionString=" ...
- Docker | 第四章:Dockerfile简单介绍及使用
前言 前一章节,介绍了Docker常用的命令.在基本使用上,熟悉这些常用的命令基本上就够了.但在一些场景下,比如在部署SpringBoot应用时,通常我们都是打成Jar包,然后利用java命令进行运行 ...
- Java基础知识——windows系统下安装JDK
(作者声明:文章引用了其他作者的文章,但因为笔记内容时间过久,已经忘记从哪里摘录下来的了.若无意间侵犯到原作者您的权利,对不起!您可以联系我,我这边会马上进行修改,谢谢!) 1.首先我们需要下载jav ...
- JSP中,EL表达式向session中取出一个attribute和JSP脚本访问session取出一个attribute,写法有何不同?(转自百度知道)
EL表达式使用起来会更简洁,假如session中有一个属性A(attrA),那么EL和jsp脚本取值的方式如下: EL表达式:${ sessionScope.attrA } JSP脚本:<%=s ...
- cf1042F. Leaf Sets(贪心)
题意 题目链接 给出一棵树,删除一些边,使得任意联通块内的任意点距离不超过$k$ sol 考场上想的贪心是对的:考虑一棵子树,如果该子树内最深的两个节点的距离相加$>k$就删掉最深的那个点,向上 ...
- 从github克隆内容到本地时权限问题
从github克隆内容到本地时权限问题
- 关于第三方dll,ocx开发的思考
A问题: 最近有个工作,要集成一套老的指纹考勤机器到现在考勤系统(web系统)中,问题出现时老的机器只有ocx可用,没有可用的dll:原本以为简单的第三方调用就ok了,可是ocx不能被承载,在实现上费 ...
- 新版graylog2安装过程
Graylog是一个开源的 log 收容器,背后的储存是搭配 mongodb,而搜寻引擎则由 elasticsearch 提供.以前版本主要有两个部分集合而成 server 与 web interfa ...
- javascript:理解DOM事件
首先,此文不讨论繁琐细节,但是考虑到读者的心灵感受,本着以积极向上的心态,在此还是会列举示例说明. 标题为理解DOM事件,那么在此拿一个简单的点击事件为例,希望大家看到这个例子后能触类旁通. DOM ...
- 测试发布(maven-assembly-plugin看好你哦)
项目改成了maven管理,现场需要用增量补丁包的形式发布代码: 2015/4/21 以前试过用ant打补丁包,现在试试maven能不能做同样的事情: maven-assembly-plugin看着可以 ...