Misty rain
言必行,行必果。
"""
@Author:Misty rain(ZhangHao)
@E-mail:676817831@qq.com
@FileName:gettime.py
@Software:PyCharm
@Desc:获取时间参数
"""
import time
import datetime
def get_system_time():
"""
获取当前时间
:return:
"""
new_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
return str(new_time)
def get_system_time_nyr():
"""
获取当前日期
:return:
"""
new_time = time.strftime('%Y-%m-%d', time.localtime())
return str(new_time)
def get_system_time_nyrsf():
"""
获取当前时间 具体到时分
:return:
"""
new_time = time.strftime('%Y-%m-%d %H:%M', time.localtime())
return str(new_time)
def get_system_time_hdata():
"""
获取当前时间的后一天
:return:
"""
now_time = datetime.datetime.now()
new_time = (now_time + datetime.timedelta(days=+1)).strftime("%Y-%m-%d %M:%S")
return str(new_time)
def get_system_time_tdata():
"""
获取当前时间的后二天
:return:
"""
now_time = datetime.datetime.now()
new_time = (now_time + datetime.timedelta(days=+2)).strftime("%Y-%m-%d %M:%S")
return str(new_time)
def get_logdata():
"""
获取当前日期
:return:
"""
new_time = time.strftime('%Y%m%d%H%M%S', time.localtime())
return str(new_time)
def get_system_time_hhours():
"""
获取当前时间的后一小时
:return:
"""
now_time = datetime.datetime.now()
new_time = (now_time + datetime.timedelta(hours=+1)).strftime("%Y-%m-%d %H:%M")
return str(new_time)
def get_system_time_hdkssj():
"""
获取当前时间的后俩小时
:return:
"""
now_time = datetime.datetime.now()
new_time = (now_time + datetime.timedelta(hours=+2)).strftime("%Y-%m-%d %H:%M")
return str(new_time)
"""
@Author:Misty rain(ZhangHao)
@E-mail:676817831@qq.com
@FileName:getfileposition.py
@Software:PyCharm
@Desc:获取文件位置公共类
"""
import os
# 获取当前目录
def getcurrent():
path = os.path.abspath(os.path.dirname(__file__))
return path
# 获取项目根目录
def getrootpath():
path = os.path.dirname(os.path.dirname(__file__))
return path
# 获取文件目录
def getfilepath():
path = os.path.dirname(os.path.dirname(__file__)) + '/file'
return path
# 调试
if __name__ == '__main__':
print(getcurrent())
print(getrootpath())
print(getfilepath())
"""
@Author:Misty rain(ZhangHao)
@E-mail:676817831@qq.com
@FileName:getlog.py
@Software:PyCharm
@Desc:
"""
import logging
import commont.getfileposition as file
import colorlog
import commont.gettime as time
# 定义全局变量
log_colors_config = {
'DEBUG': 'white',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'bold_red'
}
logger = logging.getLogger('PROJECT')
logger.setLevel(logging.DEBUG)
# 创建一个handler写入日志
fh = logging.FileHandler(
filename=file.getrootpath()+'/log/{project}.log'.format(project=time.get_system_time_nyr()))
fh.setLevel(logging.DEBUG)
# 创建一个handler输出控制台
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# 定义日志输入格式
formatter = logging.Formatter(
fmt='[%(asctime)s.%(msecs)03d] %(filename)s -> %(funcName)s line:%(lineno)d [%(levelname)s] : %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
# 控制台输出有颜色的日志
console_formatter = colorlog.ColoredFormatter(
fmt='%(log_color)s[%(asctime)s.%(msecs)03d] %(filename)s -> %(funcName)s line:%(lineno)d [%(levelname)s] '
': %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
log_colors=log_colors_config
)
# 定义日志输入格式
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s','%Y/%m/%d %H:%M:%S')
fh.setFormatter(formatter)
ch.setFormatter(console_formatter)
logger.addHandler(fh)
logger.addHandler(ch)
if __name__ == '__main__':
logger.error('error message')
logger.debug('debug message')
logger.info('info message')
logger.warning('war message')
logger.critical('cri message')
备案号: 浙ICP备2021040483号
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
555
555
555
555
555
555
1
1
1
1
1
1
555
555
1
1
1
response.write(9679664*9332124)
'+response.write(9679664*9332124)+'
"+response.write(9679664*9332124)+"
1
-5 OR 535=(SELECT 535 FROM PG_SLEEP(15))--
1