> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-logging/runtime-config-logging-jsonlog.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 19.8.5. 使用 JSON 格式日誌輸出

## 19.8.5. 使用 JSON 格式日誌輸出 [#](#runtime-config-logging-jsonlog) <a href="#runtime-config-logging-jsonlog" id="runtime-config-logging-jsonlog"></a>

在 `log_destination` 清單中包含 `jsonlog`，能提供一種方便的方式， 將日誌檔案匯入許多不同的程式。此選項會以 JSON 格式輸出日誌行。

值為 null 的字串欄位不會出現在輸出中。 未來可能會加入更多欄位。處理 `jsonlog` 輸出的使用者應用程式， 應忽略未知的欄位。

每一行日誌都會序列化為一個 JSON 物件，其中包含 [表 19.4](#runtime-config-logging-jsonlog-keys-values) 所示的鍵集合及其對應的值。

### 表 19.4. JSON 日誌項目的鍵與值 [#](#runtime-config-logging-jsonlog-keys-values) <a href="#runtime-config-logging-jsonlog-keys-values" id="runtime-config-logging-jsonlog-keys-values"></a>

| 鍵名稱                 | 類型     | 說明                 |
| ------------------- | ------ | ------------------ |
| `timestamp`         | string | 含毫秒的時間戳記           |
| `user`              | string | 使用者名稱              |
| `dbname`            | string | 資料庫名稱              |
| `pid`               | number | 程序 ID              |
| `remote_host`       | string | 用戶端主機              |
| `remote_port`       | number | 用戶端連接埠             |
| `session_id`        | string | 工作階段 ID            |
| `line_num`          | number | 每個工作階段的行編號         |
| `ps`                | string | 目前的 ps 顯示內容        |
| `session_start`     | string | 工作階段開始時間           |
| `vxid`              | string | 虛擬交易 ID            |
| `txid`              | string | 一般交易 ID            |
| `error_severity`    | string | 錯誤嚴重性              |
| `state_code`        | string | SQLSTATE 代碼        |
| `message`           | string | 錯誤訊息               |
| `detail`            | string | 錯誤訊息詳情             |
| `hint`              | string | 錯誤訊息提示             |
| `internal_query`    | string | 導致此錯誤的內部查詢         |
| `internal_position` | number | 內部查詢中的游標索引         |
| `context`           | string | 錯誤上下文              |
| `statement`         | string | 用戶端提供的查詢字串         |
| `cursor_position`   | number | 查詢字串中的游標索引         |
| `func_name`         | string | 錯誤位置的函式名稱          |
| `file_name`         | string | 錯誤位置的檔案名稱          |
| `file_line_num`     | number | 錯誤位置的檔案行號          |
| `application_name`  | string | 用戶端應用程式名稱          |
| `backend_type`      | string | 後端類型               |
| `leader_pid`        | number | 作用中平行工作者之領導者的程序 ID |
| `query_id`          | number | 查詢 ID              |

<br>

[返回 19.8. 錯誤回報與日誌記錄](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-logging.md#runtime-config-logging)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/runtime-config-logging.html)（原文版本：18.6；核對日期：2026-10-23）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-logging/runtime-config-logging-jsonlog.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
