跳转到主要内容

将Eliot日志渲染为ASCII树

项目描述

build coverage

Eliot日志渲染为ASCII树。

此输出

https://github.com/jonathanj/eliottree/raw/master/doc/example_eliot_log.png

(或作为文本)

$ eliot-tree eliot.log
f3a32bb3-ea6b-457c-aa99-08a3d0491ab4
└── app:soap:client:request/1  started 2015-03-03 04:28:56  1.238s
    ├── dump: /home/user/dump_files/20150303/1425356936.28_Client_req.xml
    ├── soapAction: a_soap_action
    ├── uri: http://example.org/soap
    ├── app:soap:client:success/2/1  started 2015-03-03 04:28:57  0.000s
       └── app:soap:client:success/2/2  succeeded 2015-03-03 04:28:57
           └── dump: /home/user/dump_files/20150303/1425356937.52_Client_res.xml
    └── app:soap:client:request/3  succeeded 2015-03-03 04:28:57
        └── status: 200

 89a56df5-d808-4a7c-8526-e603aae2e2f2
 └── app:soap:service:request/1  started 2015-03-03 04:31:08  3.482s
     ├── dump: /home/user/dump_files/20150303/1425357068.03_Service_req.xml
     ├── soapAction: method
     ├── uri: /endpoints/soap/method
     ├── app:soap:service:success/2/1  started 2015-03-03 04:31:11  0.001s
        └── app:soap:service:success/2/2  succeeded 2015-03-03 04:31:11
            └── dump: /home/user/dump_files/20150303/1425357071.51_Service_res.xml
     └── app:soap:service:request/3  succeeded 2015-03-03 04:31:11
         └── status: 200

{"dump": "/home/user/dump_files/20150303/1425356936.28_Client_req.xml", "timestamp": 1425356936.278875, "uri": "http://example.org/soap", "action_status": "started", "task_uuid": "f3a32bb3-ea6b-457c-aa99-08a3d0491ab4", "action_type": "app:soap:client:request", "soapAction": "a_soap_action", "task_level": [1]}
{"timestamp": 1425356937.516579, "task_uuid": "f3a32bb3-ea6b-457c-aa99-08a3d0491ab4", "action_type": "app:soap:client:success", "action_status": "started", "task_level": [2, 1]}
{"task_uuid": "f3a32bb3-ea6b-457c-aa99-08a3d0491ab4", "action_type": "app:soap:client:success", "dump": "/home/user/dump_files/20150303/1425356937.52_Client_res.xml", "timestamp": 1425356937.517077, "action_status": "succeeded", "task_level": [2, 2]}
{"status": 200, "task_uuid": "f3a32bb3-ea6b-457c-aa99-08a3d0491ab4", "task_level": [3], "action_type": "app:soap:client:request", "timestamp": 1425356937.517161, "action_status": "succeeded"}
{"dump": "/home/user/dump_files/20150303/1425357068.03_Service_req.xml", "timestamp": 1425357068.032091, "uri": "/endpoints/soap/method", "action_status": "started", "task_uuid": "89a56df5-d808-4a7c-8526-e603aae2e2f2", "action_type": "app:soap:service:request", "soapAction": "method", "task_level": [1]}
{"timestamp": 1425357071.51233, "task_uuid": "89a56df5-d808-4a7c-8526-e603aae2e2f2", "action_type": "app:soap:service:success", "action_status": "started", "task_level": [2, 1]}
{"task_uuid": "89a56df5-d808-4a7c-8526-e603aae2e2f2", "action_type": "app:soap:service:success", "dump": "/home/user/dump_files/20150303/1425357071.51_Service_res.xml", "timestamp": 1425357071.513453, "action_status": "succeeded", "task_level": [2, 2]}
{"status": 200, "task_uuid": "89a56df5-d808-4a7c-8526-e603aae2e2f2", "task_level": [3], "action_type": "app:soap:service:request", "timestamp": 1425357071.513992, "action_status": "succeeded"}

命令行选项

查看eliot-tree --help的输出以获取命令行选项的完整列表。

流式处理

可以将数据导入到eliot-tree,例如从跟踪日志中,并逐步渲染。但有一个警告:只有当树根操作的结束消息(成功或失败状态)出现在数据中时,才会渲染树。

选择/过滤任务

通过任务UUID

可以使用--task-uuid (-u) 命令行选项通过UUID选择整个任务树。

通过开始/结束日期

可以根据时间戳选择单个任务,使用--start选择ISO8601日期时间之后的任务,并使用--end选择ISO8601日期时间之前的任务。

通过自定义查询

可以使用--select命令行选项进行自定义任务选择,其语法为JMESPath,并应用于原始的Eliot JSON结构。可以查询任何出现在Eliot任务结构中的数据。只有匹配的任务(及其所有子任务)将被显示,任务结构的父级(通过task_uuid)将被省略。

需要注意的重要一点是,查询应该用作谓词(它应该描述一个布尔条件),而不是缩小JSON数据结构,正如JMESPath网站上的许多示例所说明的那样。这样做的原因是Eliot任务不是以一个大型的嵌套JSON结构存储的,而是由元数据(task_uuid)链接的许多小结构,这不是JMESPath理想查询的结构。

--select参数可以多次提供以模拟逻辑AND,也就是说,所有--select谓词都必须通过,才能选择一个任务或节点。

示例

选择所有包含uri键的任务,无论其值如何

--select 'uri'

选择所有类型为http_client:request的Eliot动作任务

--select 'action_type == `"http_client:request"`'

JMESPath中使用反引号来表示原始JSON值,`500`是数字500,`"500"`是字符串“500”。

选择所有具有401或500http_status的任务

--select 'contains(`[401, 500]`, status)'

选择所有具有401http_status且发送到包含文本/criticalEndpointuri的任务

--select 'http_status == `401`' \
--select 'uri && contains(uri, `"/criticalEndpoint"`)'

在这里,--select被传递两次以模拟逻辑AND条件,也可以使用JMESPath的&&运算符。还有一个测试用于检查uri键的存在,以防止在具有null主题的情况下调用contains()函数。

有关更多信息,请参阅JMESPath规范

程序化使用

import json, sys
from eliottree import tasks_from_iterable, render_tasks
# Or `codecs.getwriter('utf-8')(sys.stdout).write` on Python 2.
render_tasks(sys.stdout.write, tasks, colorize=True)

有关更多信息,请从Python REPL中查看help(render_tasks)help(tasks_from_iterable)

配置

可以通过配置文件指定命令行选项的默认值。可以通过--config参数传递配置文件,或者从~/.config/eliot-tree/config.json中读取。有关示例,请参阅config.example.json

使用--show-default-config命令行选项显示默认配置,适合重定向到文件。使用--show-current-config命令行选项显示当前有效配置。

主题覆盖

可以通过配置文件中的theme_overrides键覆盖主题颜色。此键的值本身是一个JSON对象,每个键是主题颜色的名称,每个值是一个JSON列表。此列表应包含三个值

  1. 前景颜色,终端颜色名称或代码;或null以使用默认颜色。

  2. 背景颜色,终端颜色名称或代码;或null以使用默认颜色。

  3. 一个可选的颜色属性名称或代码数组;或null以使用默认属性。

例如,要覆盖 root 主题颜色为鲜红色,并将 prop 主题颜色设置为红色

{
  "theme_overrides": {
    "root": ["magenta", null, ["bold"]],
    "prop_key": ["red"]
  }
}

请参阅 _theme.py 了解主题颜色名称,以及 colored Python 包中可用的颜色和属性常量。

贡献

有关详细信息,请参阅 https://github.com/jonathanj/eliottree

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

eliot-tree-21.0.0.tar.gz (50.0 kB 查看散列值)

上传时间 源代码

构建分发

eliot_tree-21.0.0-py3-none-any.whl (40.1 kB 查看散列值)

上传时间 Python 3

由以下组织支持: