12. 调试通道¶
在 CubicWeb 3.27添加了一个新的调试通道机制来帮助构建金字塔调试工具栏自定义面板。它并不意味着要进行常规的CW开发,但是如果需要,可以用于工具构建(比如定制面板)。
API的使用非常简单,使用方式如下:
from cubicweb.debug import subscribe_to_debug_channel, unsubscribe_to_debug_channel
# the callback will only receive one argument which is a python dict
# containing debug information
def example_debug_callback(message):
print(message)
# "channel" must be one of: controller, rql, sql, vreg, registry_decisions
subscribe_to_debug_channel(channel, example_debug_callback)
# when it is not needed anymore (and to avoid dandling references)
unsubscribe_to_debug_channel(channel, example_debug_callback)
12.1. 渠道文件¶
按频道发送的消息列表:
12.1.1. 控制器¶
此调试消息将仅在金字塔上下文中发送 . 为每个请求发出。
{
"kind": ctrlid,
"request": request_object,
"path": request_object.path,
"controller": controller,
"config": repo_configuration,
}
12.1.2. RQL¶
为每个查询发出。
{
"rql": rql_as_a_string,
# arguments used to format the query
"args": args,
# used to link rql and sql queries
"rql_query_tracing_token": rql_query_tracing_token,
"callstack": python_call_stack,
"time": time_taken_in_ms_by_the_query,
"result": the_result_as_python_data,
"description": description_object,
}
12.1.3. SQL¶
为每个查询发出。请注意,由RQL查询生成的SQL查询将在相应的RQL查询之前发出。
{
"sql": sql_as_a_string,
# arguments used to format the query
"args": args,
"rollback": True|False,
"callstack": "".join(traceback.format_stack()[:-1]),
# used to link rql and sql queries
"rql_query_tracing_token": rql_query_tracing_token,
"time": time_taken_in_ms_by_the_query,
}
12.1.4. 电压调整器¶
此调试消息将仅在金字塔上下文中发送 . 为每个请求发出。
{
"vreg": vreg,
}
12.1.5. registry_decisions¶
每次在注册表中做出决策时,都会发出此消息。
{
"all_objects": [],
"end_score": int,
"winners": [],
"winner": obj or None,
"registry": obj,
"args": args,
"kwargs": kwargs,
}