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:/ ...
随机推荐
- jQuery jQuery on()方法
jQuery on()方法是官方推荐的绑定事件的一个方法. $(selector).on(event,childSelector,data,function,map) 由此扩展开来的几个以前常见的方法 ...
- java-类的定义和用法
1.类的定义 public class Human{ }//每个源文件必须也只能有一个public类 class boy{ }//可以定义多个class类 class girl{ } 上面的类定义好后 ...
- 玩转Docker之常用API(四)
原文地址:http://accjiyun.cn/wan-zhuan-dockerzhi-chang-yong-api-si/ 任何一个开发的平台都会向开发者开发API,以供开发者更加自由地使用平台所提 ...
- JVM(二):垃圾回收
三个问题: 那些内存需要回收? -- 对象是否存活判断 什么时候回收? --垃圾回收触发条件 如何回收? --垃圾回收算法 垃圾回收应用 -- 理解GC日志.使用垃圾回收命令和工具 1. 判断 ...
- 少写代码帮你模块化方法 & 运动框架 & 简化轮播图
模块化就是通过每一个js里封装一个方法:用exports将他输出, 在下一个js用require的方法加载js时就会将方法输出.然后在主页面引入require.js; 模块化基本写法: define( ...
- 初学者:Git常用命令总结
git init 在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前文件夹下创建一个.git文件夹. git clone 获取一个u ...
- ionic 2 起航 控件的使用 客户列表场景(三)
我们来看看客户列表的搜索控件是怎么工作的吧. 1.打开customer.html <ion-content> <ion-searchbar [(ngModel)]="sea ...
- 调用cmd命令行命令(借鉴)
留待以后观看 ———————————————————————————————————————————————————————————————————————————— public class IP_ ...
- 2018.6.12 Oracle问题
ORA-01950: 对表空间 'USERS' 无权限 创建新的用户时,要指定default tablespace,否则它会把system表空间当成自己的缺省表空间.这样做是不提倡的.估计原来创建某个 ...
- cf1151 B
题目连接 : https://codeforces.com/contest/1151/problem/B 可能我想法有问题,我怎么感觉B题的思路不直接想出来的,我想了一会才想出来,感觉不难,但可能有更 ...