The error you're encountering is because table is not a valid LogQL command. LogQL doesn't have a table operation like SQL does.
To display logs in a table format in Grafana, you need to:
- Use a query that returns log lines (not aggregated metrics)
- Configure the Grafana panel visualization to "Logs" or "Table"
Here's the corrected query:
{label="mode_switch_logs"} |= "Switching detect mode"
| regexp "Switching detect mode to (?P<mode>MANUAL|OFF|ON) .* Sender: (?P<sender>tray|desktop).*"
How to set it up as a table in Grafana:
- Add a new panel to your dashboard
- Enter the query above (without the
table command)
- Change the visualization type:
- In the panel editor, look for the visualization selector (usually in the top-right of the panel editor)
- Select "Logs" for a log-style view, or "Table" for a more structured table view
- For Table visualization, you can configure which fields to display:
- Look for the "Transform" tab or "Table options"
- You can choose to show/hide specific fields like timestamp, labels, etc.
- The extracted labels (
mode and sender) will automatically appear as columns
Alternative: If you want a cleaner table view
You can also add | line_format "{{.mode}} | {{.sender}}" to format the log line content:
{label="mode_switch_logs"} |= "Switching detect mode"
| regexp "Switching detect mode to (?P<mode>MANUAL|OFF|ON) .* Sender: (?P<sender>tray|desktop).*"
| line_format "Mode: {{.mode}} | Sender: {{.sender}}"
This will make the log line content cleaner in the table view, showing only the extracted values in a formatted way.