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