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
|
# Перехватчики для журнала запросов 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):
|
||||||
if "query_start_time" not in conn.info:
|
conn.info.setdefault('query_start_time', []).append(time.time())
|
||||||
conn.info["query_start_time"] = []
|
logger.debug(f"{statement}")
|
||||||
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):
|
||||||
if "query_start_time" in conn.info and conn.info["query_start_time"]:
|
total = time.time() - conn.info['query_start_time'].pop(-1)
|
||||||
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' {stars} {total*1000} s')
|
||||||
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