# _*_coding:utf-8_*_
# Author:len liu
import os
import logging.config
#from interface import register
BASE_DIR=os.path.dirname(os.path.dirname(__file__))
DB_PATH = os.path.join(BASE_DIR,'db')
"""
logging配置
"""
# 定义三种日志输出格式 开始
# standard_format = '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]' \
# '[%(levelname)s][%(message)s]' #其中name为getlogger指定的名字
#
# simple_format = '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
#
# id_simple_format = '[%(levelname)s][%(asctime)s] %(message)s'
standard_format = '%(asctime)s | %(threadName)s:%(thread)d | task_id:%(name)s | %(filename)s:%(lineno)d' \
'| %(levelname)s | %(message)s' #其中name为getlogger指定的名字
simple_format = '%(levelname)s | %(asctime)s | %(filename)s:%(lineno)d | %(message)s'
id_simple_format = '%(levelname)s | %(asctime)s | %(message)s'
# 定义日志输出格式 结束
logfile_dir = os.path.join(BASE_DIR,'log') # log文件的目录
logfile_name = 'all2.log' # log文件名
# 如果不存在定义的日志目录就创建一个
if not os.path.isdir(logfile_dir):
os.mkdir(logfile_dir)
# log文件的全路径
logfile_path = os.path.join(logfile_dir, logfile_name)
# log配置字典
LOGGING_DIC = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': standard_format
},
'simple': {
'format': simple_format
},
},
'filters': {},
'handlers': {
#打印到终端的日志
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler', # 打印到屏幕
'formatter': 'simple'
},
#打印到文件的日志,收集info及以上的日志
'default': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler', # 保存到文件
'formatter': 'standard',
'filename': logfile_path, # 日志文件
#'maxBytes': 1024*1024*5, # 日志大小 5M
#'backupCount': 5,
'encoding': 'utf-8', # 日志文件的编码,再也不用担心中文log乱码了
},
},
'loggers': {
#logging.getLogger(__name__)拿到的logger配置
'': {
'handlers': ['default', 'console'], # 这里把上面定义的两个handler都加上,即log数据既写入文件又打印到屏幕
'level': 'DEBUG',
'propagate': False, # 向上(更高level的logger)传递
},
},
}
----------------------------------------------------------------------------------------------------------------------
# _*_coding:utf-8_*_
# Author:len liu
from conf import path
import json
import os
from lib import au_login
import logging
import logging.config
logging.config.dictConfig(path.LOGGING_DIC)
loggers = logging.getLogger("-交易日志-")
def register():
count=0
while count<3:
username = input('pls input your name:').strip()
passwd = input('pls input your passwd:').strip()
sec_passwd = input('pls confirm your password:').strip()
user_dic = {'name': username,'password': passwd}
userinfo_file = os.path.join(path.DB_PATH,'%s.json'%username)
if os.path.exists(userinfo_file):
print ("username already exsit!")
count += 1
else:
if passwd == sec_passwd:
with open(userinfo_file, 'wt', encoding='utf-8') as f:
json.dump(user_dic,f)
f.flush()
print('register successful!')
break
else:
print('input same password')
@au_login.auth_login
def withdraw():
print('withdraw')
loggers.info ("提款金额为xxxxxx!")
@au_login.auth_login
def transfer():
print('transfer')
loggers.info ("转账结果是xxxxxx!")
@au_login.auth_login
def query():
print('query')
loggers.info("查询结果是xxxxxx!")
def payments ():
print('payments')
loggers.info ("支付结果是xxxxxx!")
def count_manager():
print('count_manager')