如何在Grafana Explore中以易读格式展示日志?
To get a Kibana-style table view with aligned columns and headers for logs in Grafana Explore, follow these steps:
1. Switch to Table View Mode
After running your log query, locate the view mode toggle (typically in the top-right corner of the Explore window, next to the time range picker). By default, it's set to "Logs" (raw line view). Click it and select Table—this will immediately render your logs as a structured table, with each selected field as a column.
2. Customize Visible Columns
- Use the Fields panel (left sidebar) to select which fields you want to display as columns. Deselect any irrelevant fields to reduce clutter.
- Reorder fields by dragging them in the Fields panel to adjust the column order in the table to match your preferred layout.
3. Parse Unstructured Logs into Structured Fields
If your logs are unstructured (e.g., plain text), use LogQL parsers to extract structured fields that can be displayed as columns:
- For JSON logs:
{job="your-job-name"} | json | select time, message, user_id, status_code - For logfmt-formatted logs:
{job="your-job-name"} | logfmt | select time, msg, level, request_id - For custom patterns, use regex parsing:
{job="your-job-name"} | regexp `^(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) \[(?P<level>\w+)\] (?P<message>.*)` | select timestamp, level, message
These queries will extract specific fields, which will automatically become columns when you switch to Table view.
4. Enhance Readability with Table Features
- Sort Columns: Click on any column header to sort logs by that field (ascending/descending).
- Filter Columns: Hover over a column header, click the filter icon, and set criteria to narrow down logs (e.g., show only logs where
status_code=500). - Wrap Text: Enable text wrapping in the table settings (accessible via the gear icon in the top-right of the table view) to handle long message fields without excessive truncation.
内容的提问来源于stack exchange,提问作者Shadow

