

支援終止通知：2025 年 9 月 15 日， AWS 將停止對 Amazon Lex V1 的支援。2025 年 9 月 15 日之後，您將無法再存取 Amazon Lex V1 主控台或 Amazon Lex V1 資源。如果您使用的是 Amazon Lex V2，請改參閱 [Amazon Lex V2 指南](https://docs.aws.amazon.com/lexv2/latest/dg/what-is.html)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 Amazon CloudWatch Logs 中檢視文字日誌
<a name="conversation-logs-cw"></a>

Amazon Lex 會將對話的文字日誌儲存在 Amazon CloudWatch Logs 中。若要檢視日誌，您可以使用 CloudWatch Logs 主控台或 API。如需詳細資訊，請參閱《Amazon CloudWatch Logs 使用者指南》中的[使用篩選條件模式搜尋日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/SearchDataFilterPattern.html)和 CloudWatch Logs Insights 查詢語法。 [CloudWatch ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html) *Amazon CloudWatch *

**使用 Amazon Lex 主控台檢視日誌**

1. 開啟 Amazon Lex 主控台 https：//[https://console.aws.amazon.com/lex](https://console.aws.amazon.com/lex)。

1. 從清單中選擇一個機器人。

1. 選擇 **Settings (設定)** 標籤，然後從左側功能表中選擇 **Conversation logs (對話日誌)**。

1. 選擇**文字日誌**下方的連結，以在 CloudWatch 主控台中檢視別名的日誌。

您也可以使用 CloudWatch 主控台或 API 來檢視您的日誌項目。若要尋找日誌項目，請導覽至您針對別名設定的日誌群組。您可以在 Amazon Lex 主控台或使用 [GetBotAlias](API_GetBotAlias.md)操作找到日誌的日誌串流字首。

使用者表達用語的日誌項目位於多個日誌串流中。對話中的表達用語在其中一個日誌串流中具有指定前綴的項目。日誌串流中的項目包含下列資訊。

```
{
   "messageVersion": "1.0",
   "botName": "bot name",
   "botAlias": "bot alias",
   "botVersion": "bot version",
   "inputTranscript": "text used to process the request",
   "botResponse": "response from the bot",
   "intent": "matched intent",
   "nluIntentConfidence": "number",
   "slots": {
       "slot name": "slot value",
       "slot name": null,
       "slot name": "slot value"
       ...
   },
   "alternativeIntents": [
       {
           "name": "intent name",
           "nluIntentConfidence": "number",
           "slots": {
               "slot name": slot value,
               "slot name": null,
               "slot name": slot value
               ...
           }
       },
       {
           "name": "intent name",
           "nluIntentConfidence": number,
           "slots": {}
       }
   ],
   "developerOverride": "true" | "false",
   "missedUtterance": true | false,
   "inputDialogMode": "Text" | "Speech",
   "requestId": "request ID",
   "s3PathForAudio": "S3 path to audio file",
   "userId": "user ID",
   "sessionId": "session ID",
   "sentimentResponse": {
       "sentimentScore": "{Positive: number, Negative: number, Neutral: number, Mixed: number}",
       "sentimentLabel": "Positive" | "Negative" | "Neutral" | "Mixed"
   },
   "slotToElicit": "slot name",
   "dialogState": "ElicitIntent" | "ConfirmIntent" | "ElicitSlot" | "Fulfilled" | "ReadyForFulfillment" | "Failed",
   "responseCard": {
       "genericAttachments": [
           ...
       ],
       "contentType": "application/vnd.amazonaws.card.generic",
       "version": 1
    },
   "locale": "locale",
   "timestamp": "ISO 8601 UTC timestamp",
   "kendraResponse": {
      "totalNumberOfResults": number,
      "resultItems": [
          {
              "id": "query ID",
              "type": "DOCUMENT" | "QUESTION_ANSWER" | "ANSWER",
              "additionalAttributes": [
                  {
                     ...
                  }
              ],
              "documentId": "document ID",
              "documentTitle": {
                  "text": "title",
                  "highlights": null
              },
              "documentExcerpt": {
                  "text": "text",
                  "highlights": [
                      {
                          "beginOffset": number,
                          "endOffset": number,
                          "topAnswer": true | false
                      }
                  ]
              },
              "documentURI": "URI",
              "documentAttributes": []
          }  
      ],
      "facetResults": [],
      "sdkResponseMetadata": {
          "requestId": "request ID"
      },
      "sdkHttpMetadata": {
          "httpHeaders": {
              "Content-Length": "number",
              "Content-Type": "application/x-amz-json-1.1",
              "Date": "date and time",
              "x-amzn-RequestId": "request ID"
          },
          "httpStatusCode": 200
      },
      "queryId": "query ID"
   },
   "sessionAttributes": {
       "attribute name": "attribute value"
       ...
    },
   "requestAttributes": {
       "attribute name": "attribute value"
       ...
    }
}
```

日誌項目的內容取決於交易的結果以及機器人和請求的組態。
+ 若 `missedUtterance` 欄位是 `true`，則 `intent`、`slots` 和 `slotToElicit` 不會顯示在輸入中。
+ 如果音訊日誌已停用或 `inputDialogMode` 欄位是 `Text`，則 `s3PathForAudio` 欄位不會出現。
+ 只有在您為機器人定義回應卡片時，才會顯示 `responseCard` 欄位。
+ 只有在請求中指定了請求屬性時，才會顯示 `requestAttributes` 對映。
+ 只有在 `AMAZON.KendraSearchIntent`提出搜尋 Amazon Kendra 索引的請求時，才會出現 `kendraResponse` 欄位。
+ 在機器人的 Lambda 函數中指定替代意圖時， `developerOverride` 欄位為 true。
+ 只有在請求中指定了工作階段屬性時，才會顯示 `sessionAttributes` 映射。
+ 只有在您設定機器人傳回情緒值時，才會顯示 `sentimentResponse` 映射。

**注意**  
即使 `messageVersion` 中沒有對應的變更，輸入格式也可能變更。如果出現新欄位，您的程式碼不應擲出錯誤。

您必須設定角色和政策，才能讓 Amazon Lex 寫入 CloudWatch Logs。如需更多資訊，請參閱[對話日誌的 IAM 政策](conversation-logs-policies.md)。