The Vlog Query Tool is a utility to query vlogs (victorialogs) using a TOML configuration file and print the results in the terminal. This tool supports highlighting specified fields, formatting JSON output, copying to the clipboard when querying a single record, and using the Rich library for beautiful terminal output.
- Query vlogs using a TOML configuration file and print results in the terminal.
- Support for highlighting specified fields.
- Support for formatting JSON output.
- Support for copying to the clipboard when querying a single record.
- Using the Rich library for beautiful terminal output.
- Support for printing only the query and request parameters (
only_print
parameter).
Before using this tool, ensure you have installed the following Python libraries:
pip install requests pyperclip rich
Create a TOML configuration file, for example, config.toml
:
topic = "example_topic"
caller = "*"
limit = 1
start_datetime = "2024-07-29T14:00:13+08:00"
end_datetime = "2024-07-29T16:50:13+08:00"
api_url = "https://your_domain/select/logsql/query"
time_sort_order = "desc"
query = "level:* _msg:log msg _msg:* caller:*"
only_print = true
_msg = ["handleUpdateVoiceManager debug count"]
fields = [
"_msg",
"userId",
"example_field"
]
highlight_fields = [
"userId",
"RequestPath",
"topic",
"request_X-Ht-Uid",
"OriginStatus",
"caller",
"_msg",
"custom_field"
]
[customize]
[stream]
service = "example_service"
python vlog_query.py --conf config.toml
limit
: Query limit.last_duration
: Duration, e.g., "5m" means the last 5 minutes.fields
: List of fields to display.highlight_fields
: List of fields to highlight.api_url
: The query interface for vlogs._msg
: Message field, the log message printed by the code.query
: Custom query statement.only_print
: Iftrue
, only print the query and request parameters.
In the configuration file, specify the fields to highlight using the highlight_fields
field, for example:
highlight_fields = ["RequestPath", "topic", "request_X-Ht-Uid", "OriginStatus", "caller", "_msg", "custom_field"]
When the query limit is set to 1, the script will format the JSON output and copy it to the clipboard.
The script uses the Rich library to achieve beautiful terminal output, supporting field highlighting and JSON formatting.