import base64
import logging,os
from logging.handlers import RotatingFileHandler
def get_logger(file_name,size_MB,backup_count):
"""Parameters:
file_name - To define the log file name
size_MB - How munch the size of the log file need to retain
backup_count - How many backups of the log file need to retain
Returns:
Returns a logger of logging
Raises:
KeyError - raises an exception"""
if os.path.isdir('log'):
filename = os.path.join(os.getcwd(), "log/", file_name)
else:
os.mkdir('log')
filename = os.path.join(os.getcwd(), "log/", file_name)
maxlogsize = size_MB * 1024 * 1024 #Bytes
backupcount = backup_count
format = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
handler = RotatingFileHandler(filename, mode='a', maxBytes=maxlogsize, backupCount=backupcount)
formatter = logging.Formatter(format)
handler.setFormatter(formatter)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(handler)
return logger
def encode(str):
utf_str = str.encode(encoding="utf_8")
return base64.b64encode(utf_str)
def decode(encryp_data):
utf_byte = base64.b64decode(encryp_data)
return utf_byte.decode(encoding="utf_8")
_uname = decode("dm9pY2U=")
_upwd = decode("dm9pY2UyMDE5")
_dbhost = "192.000.1.000"#IP
_port = 1234#端口
_dbname = "rootname"#用户名
网友评论