logger-timing-logix-fix
All checks were successful
Deploy to core / deploy (push) Successful in 1m27s
All checks were successful
Deploy to core / deploy (push) Successful in 1m27s
This commit is contained in:
parent
731f9a45df
commit
253ee11bb9
|
@ -23,22 +23,17 @@ Base = declarative_base()
|
|||
|
||||
|
||||
# Перехватчики для журнала запросов SQLAlchemy
|
||||
@event.listens_for(Engine, "before_cursor_execute")
|
||||
@event.listens_for(Engine, 'before_cursor_execute')
|
||||
def before_cursor_execute(conn, cursor, statement, parameters, context, executemany):
|
||||
if "query_start_time" not in conn.info:
|
||||
conn.info["query_start_time"] = []
|
||||
conn.info["query_start_time"].append(time.time())
|
||||
conn.info.setdefault('query_start_time', []).append(time.time())
|
||||
logger.debug(f"{statement}")
|
||||
|
||||
|
||||
@event.listens_for(Engine, "after_cursor_execute")
|
||||
@event.listens_for(Engine, 'after_cursor_execute')
|
||||
def after_cursor_execute(conn, cursor, statement, parameters, context, executemany):
|
||||
if "query_start_time" in conn.info and conn.info["query_start_time"]:
|
||||
total = time.time() - conn.info["query_start_time"].pop()
|
||||
stars = "*" * math.floor(total * 1000)
|
||||
if stars:
|
||||
logger.debug(f"{statement}\n{stars} {total*1000} s\n")
|
||||
else:
|
||||
logger.error("query_start_time is missing or empty.")
|
||||
total = time.time() - conn.info['query_start_time'].pop(-1)
|
||||
stars = '*' * math.floor(total*1000)
|
||||
if stars:
|
||||
logger.debug(f' {stars} {total*1000} s')
|
||||
|
||||
|
||||
def local_session(src=""):
|
||||
|
|
Loading…
Reference in New Issue
Block a user