修复log隔天打印日志问题
This commit is contained in:
parent
7846f32458
commit
3769b8ab97
@ -4,6 +4,7 @@ from utils.log import Log
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
log = Log().getlog()
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
@ -11,8 +12,7 @@ def index():
|
||||
|
||||
@app.route('/convert', methods=['POST'])
|
||||
def convert_sql():
|
||||
# 创建一个新的Log实例,确保每天创建一个新的日志文件
|
||||
log = Log().getlog()
|
||||
|
||||
sql_input = request.form['sql']
|
||||
hologres_connection = request.form['hologresConnection']
|
||||
log.info("SQL Input: %s", sql_input)
|
||||
|
21
utils/log.py
21
utils/log.py
@ -32,7 +32,10 @@ class Log():
|
||||
ch = logging.StreamHandler()
|
||||
ch.setLevel(logging.INFO)
|
||||
|
||||
formatter = logging.Formatter('[%(asctime)s] %(filename)s line:%(lineno)d [%(levelname)s]%(message)s')
|
||||
formatter = logging.Formatter(
|
||||
'[%(asctime)s] %(filename)s line:%(lineno)d [%(levelname)s]%(message)s',
|
||||
datefmt="%Y-%m-%d %H:%M:%S"
|
||||
)
|
||||
fh.setFormatter(formatter)
|
||||
ch.setFormatter(formatter)
|
||||
|
||||
@ -40,9 +43,9 @@ class Log():
|
||||
self.logger.addHandler(ch)
|
||||
|
||||
def getlog(self):
|
||||
today = datetime.now().strftime("%Y_%m_%d")
|
||||
current_date = datetime.now().strftime("%Y_%m_%d")
|
||||
log_date = os.path.basename(self.log_name).split('.')[0]
|
||||
if today != log_date:
|
||||
if current_date != log_date:
|
||||
self.update_log_file()
|
||||
return self.logger
|
||||
|
||||
@ -50,9 +53,17 @@ class Log():
|
||||
logger = self.getlog()
|
||||
logger.info(msg, *args, **kwargs)
|
||||
|
||||
def error(self, msg, *args, **kwargs):
|
||||
logger = self.getlog()
|
||||
logger.error(msg, *args, **kwargs)
|
||||
|
||||
def warning(self, msg, *args, **kwargs):
|
||||
logger = self.getlog()
|
||||
logger.warning(msg, *args, **kwargs)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
log = Log().getlog()
|
||||
log = Log()
|
||||
log.info("---测试开始----")
|
||||
log.error("操作步骤1,2,3")
|
||||
log.warning("----测试结束----")
|
||||
log.warning("----测试结束----")
|
@ -3,9 +3,11 @@ import sqlglot
|
||||
from sqlglot.expressions import ColumnDef
|
||||
from utils.log import Log
|
||||
|
||||
def odps(schema,table_name,columns,colmapping,hologres_connection):
|
||||
log = Log().getlog()
|
||||
|
||||
odps_sql=f'''
|
||||
|
||||
def odps(schema, table_name, columns, colmapping, hologres_connection):
|
||||
odps_sql = f'''
|
||||
CREATE EXTERNAL TABLE IF NOT EXISTS {table_name}
|
||||
(
|
||||
{columns}
|
||||
@ -22,9 +24,8 @@ TBLPROPERTIES (
|
||||
'''
|
||||
return odps_sql
|
||||
|
||||
|
||||
def extract_create_table(sql_script):
|
||||
# 创建一个新的Log实例,确保每天创建一个新的日志文件
|
||||
log = Log().getlog()
|
||||
# 解析 SQL 脚本
|
||||
parsed = sqlparse.parse(sql_script)
|
||||
|
||||
@ -49,9 +50,8 @@ def extract_create_table(sql_script):
|
||||
|
||||
return "\n".join(create_table_statements)
|
||||
|
||||
def parse_create_table_sql(create_table_sql,hologres_connection):
|
||||
# 创建一个新的Log实例,确保每天创建一个新的日志文件
|
||||
log = Log().getlog()
|
||||
|
||||
def parse_create_table_sql(create_table_sql, hologres_connection):
|
||||
|
||||
result = extract_create_table(create_table_sql)
|
||||
|
||||
@ -74,12 +74,12 @@ def parse_create_table_sql(create_table_sql,hologres_connection):
|
||||
# 如果是TEXT类型,则转换为STRING
|
||||
if column_type == 'TEXT':
|
||||
column_type = 'STRING'
|
||||
columns.append(column_name+" "+column_type)
|
||||
colmapping.append(column_name+":"+column_name)
|
||||
columns.append(column_name + " " + column_type)
|
||||
colmapping.append(column_name + ":" + column_name)
|
||||
# 将columns,colmapping转换成字符串用,分割
|
||||
columns_str = ",\n".join(columns)
|
||||
colmapping_str = ",".join(colmapping)
|
||||
table_name_str=str(table_name).split('.')[-1]
|
||||
schema=str(table_name).split('.')[0]
|
||||
table_name_str = str(table_name).split('.')[-1]
|
||||
schema = str(table_name).split('.')[0]
|
||||
|
||||
return odps(schema,table_name_str,columns_str,colmapping_str,hologres_connection)
|
||||
return odps(schema, table_name_str, columns_str, colmapping_str, hologres_connection)
|
||||
|
Loading…
x
Reference in New Issue
Block a user