The alert fires, you open the log, and the failing query is in there somewhere: one long line that starts with a timestamp and a severity label, runs through an error message, and ends with the SQL itself, compressed into a single string with no line breaks. The error names a column, or points at a position in the statement, but in a one-line query you cannot see where one clause ends and the next begins. Checking the part it names means counting commas in a wall of text.

This guide shows a short workflow for that moment: lift just the SQL out of the log line, run it through the free SQL Formatter on Ovatly, and read the result clause by clause against the error message. It is equally clear about the limits. The formatter does not parse your log for you, and it cannot tell you why the query failed. What it does is make the query readable enough to check.

Contents

  • Quick answer
  • What a log line does to a query
  • Lift the statement out first
  • How to format a logged query, step by step
  • Worked example: one log line, one readable query
  • Limitations and alternatives
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

Copy only the SQL statement out of the log line, leaving the timestamp, severity label and error text behind. Paste it into the SQL Formatter, choose the dialect of the database that wrote the log, and press Format SQL. The query comes back with keywords in upper case and each clause on its own line, so you can check the exact clause the error message names. Formatting changes layout and keyword case only; the tool does not connect to a database, so it cannot reproduce the error or confirm that a fix will run.

What a log line does to a query

Application code usually holds a query as a single string, and the log records it the same way: flat, unbroken, and wrapped in whatever the logging setup adds around it. A timestamp and severity label come first, then the error text, then the statement, sometimes with a request ID or a stack reference trailing after it. None of that wrapping is SQL, but all of it sits on the same line as the query you need to read.

Two more features of logged queries work against quick reading. The first is length: the queries that fail in production are rarely the short ones, and a join across three tables with a filter and a sort does not fit in a glance. The second is placeholders. Many applications log the statement with its parameters shown as placeholders rather than values, so the filter you are squinting at reads as a symbol instead of the value that actually ran. Both are reasons to get the statement out of the log line and into a layout built for reading before you start reasoning about it.

Lift the statement out first

The formatter formats the SQL you paste into it, so the extraction step is yours. Start where the statement starts, usually at its first keyword, and copy through to the end of the statement. Leave the timestamp, the severity label and the error text behind; pasted along with the query, they can stop it formatting cleanly. If the log line carries a stack trace or a request ID after the statement, leave that behind too.

Placeholders need no special handling. Formatting keeps placeholders, identifiers, values and string literals exactly as written, so a parameter marker in the logged query stays a parameter marker in the formatted one. If the log recorded several failing statements together, you can paste them together and they are formatted in sequence, separated by blank lines, which is handy when an incident produced a small burst of failures from the same code path.

How to format a logged query, step by step

  1. Find the failing line in the log and copy just the SQL statement out of it, without the log prefix or the error text.
  2. Open the SQL Formatter and paste the statement into the input box.
  3. Choose the dialect your database uses, matching the system that produced the log.
  4. Press Format SQL.
  5. Read the formatted query clause by clause, checking the part the error message names. Copy the result, or download it if you want to attach it to an incident note.

Worked example: one log line, one readable query

Here is the kind of line an incident leaves behind, with a mid-length SELECT buried inside it:

2026-11-27 02:14:55 ERROR [db] Query failed: column o.creted_at does not exist | query: select u.id, u.name, u.email from users u join orders o on o.user_id = u.id where o.status = $1 and o.total > 100 order by o.creted_at desc limit 20

Lift the statement out, choose the matching dialect, and Format SQL returns it in the tool's layout:

SELECT
  u.id,
  u.name,
  u.email
FROM
  users u
JOIN
  orders o ON o.user_id = u.id
WHERE
  o.status = $1
  AND o.total > 100
ORDER BY
  o.creted_at DESC
LIMIT
  20

Now the error message has something to point at. It names o.creted_at, and the ORDER BY clause sits on its own lines where the name is easy to inspect: the column is misspelled, missing the a of created_at, which the correctly spelled references elsewhere make visible once each clause is separated. Note what formatting did not touch. The $1 placeholder is still a placeholder, the table and column names are exactly as written, and the limit is unchanged. Only the layout and the keyword case moved.

Limitations and alternatives

The formatter does not parse logs. It will not find the query inside a log file, separate it from the error text, or group related lines; the lifting step in this guide is manual because the tool's job starts with SQL in the input box.

It also cannot explain the failure. The formatter does not connect to any database and cannot tell you whether a query will run or return rows, so it cannot reproduce the error, confirm your reading of it, or verify a fix. Running the corrected statement against the database, or through whatever query tool your team uses for that, is still the step that proves anything.

Dialect choice matters more with logged queries than with hand-written ones, because you did not choose the syntax in front of you. Some syntax, like MySQL backticks or T-SQL brackets, only parses correctly in its own dialect, and a mismatch is a common reason a pasted statement fails to format. An unfinished statement is the other common cause: if the log itself cut the query off, what you paste is incomplete, and the formatter may refuse it until you find the full text.

Common mistakes

  • Pasting the whole log line. Timestamps, severity labels and error text are not SQL. Paste them along with the statement and you give the formatter text it cannot lay out.
  • Choosing the wrong dialect. The dialect belongs to the database that wrote the log, not to the database you happen to use most. A mismatch can make valid syntax fail to format.
  • Expecting the formatter to explain the error. It gives you a readable query, not a diagnosis. The error message plus your knowledge of the schema still does the explaining.
  • Hunting for the real values inside the formatted output. Placeholders stay placeholders. If the failure depends on the actual parameter values, those live in your application's logging, not in the statement.
  • Skipping the clause the error names. The point of the exercise is the targeted check. Read the named clause first, then scan the rest.

FAQs

Can the formatter extract the query from my log line automatically? No. The tool formats the SQL you paste into it, so copy just the statement out of the log line first. Timestamps, severity labels and error text pasted along with the query can stop it formatting cleanly.

Will formatting tell me why the query failed? No. The formatter does not connect to any database and cannot reproduce or explain the error. What it gives you is a readable layout, so you can check the clause the error message points at.

My logged query shows placeholders instead of values. Does formatting change them? No. Placeholders, identifiers, values and string literals are left exactly as written. Only the layout and the case of keywords change.

Which dialect should I choose for a logged query? The dialect of the database that produced the log. Some syntax, like MySQL backticks or T-SQL brackets, only parses correctly in its own dialect, and a mismatch is a common reason a statement fails to format.

Is the query I paste uploaded anywhere? No. Formatting runs entirely in your browser, which matters when a log line contains schema details or other sensitive text.

Conclusion

A log line is a container, not a reading format. Lift the statement out, run it through the SQL Formatter, and the error message becomes a pointer you can follow clause by clause instead of a riddle inside a wall of text. If the formatted output raises the question of why the keywords shout in upper case, the companion guide on uppercase vs lowercase keywords in SQL covers the style side, and the rest of this series lives in the Developer Tools guides archive.