Home/Blog/MyBatis Log Formatter Guide
Tool GuideJune 15, 2026·5 min read

How to Use the MyBatis Log Formatter

Turn split Preparing / Parameters log lines into a single runnable SQL statement.

What is the MyBatis Log Formatter?

When MyBatis (or iBatis) executes a SQL query, it writes two separate lines to the log:

  • A Preparing line containing the SQL template with ? placeholders
  • A Parameters line listing each value with its Java type in parentheses

The MyBatis Log Formatter merges these two lines into a single, executable SQL statement — then formats it with proper indentation so you can run it directly in your database client.

What the Raw Log Looks Like

Here is a typical MyBatis debug log output (from Logback or Log4j):

2026-06-15 10:23:41 DEBUG c.e.mapper.UserMapper - ==>  Preparing: SELECT id, name, email FROM user WHERE id = ? AND active = ?
2026-06-15 10:23:41 DEBUG c.e.mapper.UserMapper - ==> Parameters: 42(Integer), true(Boolean)

After processing, the tool produces:

SELECT
  id,
  name,
  email
FROM
  user
WHERE
  id = 42
  AND active = true

Step-by-Step: How to Use It

  1. Open the MyBatis Log Formatter.
  2. Copy the relevant log lines from your terminal, log file, or IDE console.
  3. Paste them into the Input panel on the left.
  4. The tool automatically finds Preparing: and Parameters: lines, merges them, and formats the result in the Output panel on the right.
  5. Click Copy to copy the SQL to your clipboard, then paste it into your database client (DBeaver, DataGrip, MySQL Workbench, psql, etc.).

You do not need to remove logger prefixes, timestamps, or class names — the tool strips them automatically.

Supported Java Types

The Parameters line annotates each value with its Java type in parentheses, for example 42(Integer) or 'Alice'(String). The formatter knows how to convert each type to the correct SQL literal:

| Java Type | SQL Output | |---|---| | Integer, Long, Short, Byte | Bare number: 42 | | Double, Float, BigDecimal | Decimal number: 3.14 | | String | Quoted string: 'Alice' | | Boolean | true or false | | Timestamp, Date, LocalDateTime | Quoted string: '2026-06-15 10:23:41' | | LocalDate | Quoted string: '2026-06-15' | | null | NULL |

Handling Multiple SQL Statements

If you paste a block of logs containing several queries, the tool processes each Preparing / Parameters pair independently and outputs all the SQL statements in order. This is useful when debugging a sequence of queries that make up a single business transaction.

==>  Preparing: SELECT * FROM order WHERE id = ?
==> Parameters: 100(Long)
==>  Preparing: UPDATE order SET status = ? WHERE id = ?
==> Parameters: shipped(String), 100(Long)

Produces two separate, formatted SQL statements.

Logger Format Compatibility

The tool handles logs from the most common Java logging frameworks without any manual cleanup:

  • Logback — strips timestamps, thread names, logger names, and log levels
  • Log4j / Log4j2 — same as Logback
  • SLF4J — strips the SLF4J prefix
  • Spring Boot default logging — fully supported
  • Plain console output — the ==> Preparing: and ==> Parameters: markers are found regardless of surrounding text

Tips and Tricks

Paste the full log block. You do not need to isolate the Preparing and Parameters lines — paste a large log section and the tool will find all the relevant lines automatically.

Multiple parameters with the same type. If all your parameters are of the same type, verify the order matches the ? placeholders. MyBatis always lists them in left-to-right order.

null parameters. MyBatis logs null parameters as null(null). The tool correctly converts these to the SQL NULL literal.

Running the SQL. Once you copy the output, you can paste it directly into your database GUI. For longer queries, paste it through the SQL Formatter first to adjust keyword casing to your team's convention.

Inspect a query from production logs. Copy the relevant log lines from a production log file, paste them in, and get a runnable query instantly — useful for reproducing a bug reported with log evidence.

Related Tools