修复log隔天打印日志问题
This commit is contained in:
parent
7846f32458
commit
3769b8ab97
@ -4,6 +4,7 @@ from utils.log import Log
|
|||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
log = Log().getlog()
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
@ -11,8 +12,7 @@ def index():
|
|||||||
|
|
||||||
@app.route('/convert', methods=['POST'])
|
@app.route('/convert', methods=['POST'])
|
||||||
def convert_sql():
|
def convert_sql():
|
||||||
# 创建一个新的Log实例,确保每天创建一个新的日志文件
|
|
||||||
log = Log().getlog()
|
|
||||||
sql_input = request.form['sql']
|
sql_input = request.form['sql']
|
||||||
hologres_connection = request.form['hologresConnection']
|
hologres_connection = request.form['hologresConnection']
|
||||||
log.info("SQL Input: %s", sql_input)
|
log.info("SQL Input: %s", sql_input)
|
||||||
|
19
utils/log.py
19
utils/log.py
@ -32,7 +32,10 @@ class Log():
|
|||||||
ch = logging.StreamHandler()
|
ch = logging.StreamHandler()
|
||||||
ch.setLevel(logging.INFO)
|
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)
|
fh.setFormatter(formatter)
|
||||||
ch.setFormatter(formatter)
|
ch.setFormatter(formatter)
|
||||||
|
|
||||||
@ -40,9 +43,9 @@ class Log():
|
|||||||
self.logger.addHandler(ch)
|
self.logger.addHandler(ch)
|
||||||
|
|
||||||
def getlog(self):
|
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]
|
log_date = os.path.basename(self.log_name).split('.')[0]
|
||||||
if today != log_date:
|
if current_date != log_date:
|
||||||
self.update_log_file()
|
self.update_log_file()
|
||||||
return self.logger
|
return self.logger
|
||||||
|
|
||||||
@ -50,9 +53,17 @@ class Log():
|
|||||||
logger = self.getlog()
|
logger = self.getlog()
|
||||||
logger.info(msg, *args, **kwargs)
|
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__":
|
if __name__ == "__main__":
|
||||||
log = Log().getlog()
|
log = Log()
|
||||||
log.info("---测试开始----")
|
log.info("---测试开始----")
|
||||||
log.error("操作步骤1,2,3")
|
log.error("操作步骤1,2,3")
|
||||||
log.warning("----测试结束----")
|
log.warning("----测试结束----")
|
@ -3,8 +3,10 @@ import sqlglot
|
|||||||
from sqlglot.expressions import ColumnDef
|
from sqlglot.expressions import ColumnDef
|
||||||
from utils.log import Log
|
from utils.log import Log
|
||||||
|
|
||||||
def odps(schema,table_name,columns,colmapping,hologres_connection):
|
log = Log().getlog()
|
||||||
|
|
||||||
|
|
||||||
|
def odps(schema, table_name, columns, colmapping, hologres_connection):
|
||||||
odps_sql = f'''
|
odps_sql = f'''
|
||||||
CREATE EXTERNAL TABLE IF NOT EXISTS {table_name}
|
CREATE EXTERNAL TABLE IF NOT EXISTS {table_name}
|
||||||
(
|
(
|
||||||
@ -22,9 +24,8 @@ TBLPROPERTIES (
|
|||||||
'''
|
'''
|
||||||
return odps_sql
|
return odps_sql
|
||||||
|
|
||||||
|
|
||||||
def extract_create_table(sql_script):
|
def extract_create_table(sql_script):
|
||||||
# 创建一个新的Log实例,确保每天创建一个新的日志文件
|
|
||||||
log = Log().getlog()
|
|
||||||
# 解析 SQL 脚本
|
# 解析 SQL 脚本
|
||||||
parsed = sqlparse.parse(sql_script)
|
parsed = sqlparse.parse(sql_script)
|
||||||
|
|
||||||
@ -49,9 +50,8 @@ def extract_create_table(sql_script):
|
|||||||
|
|
||||||
return "\n".join(create_table_statements)
|
return "\n".join(create_table_statements)
|
||||||
|
|
||||||
|
|
||||||
def parse_create_table_sql(create_table_sql, hologres_connection):
|
def parse_create_table_sql(create_table_sql, hologres_connection):
|
||||||
# 创建一个新的Log实例,确保每天创建一个新的日志文件
|
|
||||||
log = Log().getlog()
|
|
||||||
|
|
||||||
result = extract_create_table(create_table_sql)
|
result = extract_create_table(create_table_sql)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user