使用平台日志

本页面介绍了如何将 Live Stream API 生成的平台日志用作 Cloud Logging 的一部分。Live Stream API 使用 Logging API 服务名称 livestream.googleapis.com 来记录与频道相关的活动。

准备工作

启用平台日志记录

默认情况下,Live Stream API 的 livestream.googleapis.com/channel_activities 平台日志处于停用状态。如需激活日志,您需要在创建或更新渠道资源时指定严重级别。

如需激活日志,请将以下字段添加到 projects.locations.channels.createprojects.locations.channels.patch 方法的请求 JSON 正文中:

   "logConfig": {
     "logSeverity": "SEVERITY_LEVEL"
   },
  

其中 SEVERITY_LEVEL 是以下值之一:

  • OFF
  • DEBUG
  • INFO
  • WARNING
  • ERROR

为渠道选择日志严重级别后,系统只会记录严重级别不低于所选严重级别的平台日志。例如,如果严重级别为 WARNING,则系统仅记录严重级别为 WARNINGERROR 的日志。如果严重级别为 INFO,则系统会记录除 DEBUG 之外的所有严重级别的日志。

如需详细了解日志严重级别,请参阅 LogSeverity

查看平台日志

如需查看平台日志,请按照以下说明操作:

控制台

如需在 Google Cloud 控制台中查看平台日志,请执行以下操作:

  1. 导航到日志浏览器:

    前往日志浏览器

  2. 选择相应的 Google Cloud 项目。

  3. 查询字段中,输入以下查询命令:

    resource.labels.channel_id=CHANNEL_ID
    resource.labels.location=LOCATION
    logName="projects/PROJECT_ID/logs/livestream.googleapis.com%2Fchannel_activities"
    

    其中:

    • CHANNEL_ID 是要调试或监控的频道的 ID。例如 my-channel

    • LOCATION 是要调试或监控的渠道的位置。例如 us-central1

    • PROJECT_ID 是包含要调试或监控的渠道的项目的 ID。例如 my-project

  4. 点击运行查询

如需详细了解日志浏览器,请参阅日志浏览器概览使用日志浏览器

gcloud

gcloud 命令行工具提供了用于 Cloud Logging 的命令行界面。

如需查看项目的 channel_activities 日志,请运行以下命令:

gcloud logging read "logName:projects/PROJECT_ID/logs/livestream.googleapis.com%2Fchannel_activities" --project=PROJECT_ID

其中,PROJECT_ID 是您的 Google Cloud 项目的 ID。

如需详细了解如何将 gcloud 工具与 Cloud Logging 搭配使用,请参阅 gcloud logging

使用平台日志

本部分介绍如何使用和解读 Live Stream API 的特定平台日志。

eventStateChange

当渠道事件的状态发生变化时,系统会生成 eventStateChange 日志。当渠道事件的新状态为 FAILED 时,eventStateChange 日志的严重级别为 ERROR。否则,eventStateChange 日志的严重级别为 INFO

以下是 eventStateChange 日志的示例:

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    eventStateChange: {
      eventId: "my-ad-break"
      newState: "SCHEDULED"
      previousState: "PENDING"
    }
    message: "State of event "my-ad-break" changed from "PENDING" to "SCHEDULED"."
  }
  ...
  severity: "INFO"
  ...
}

scte35CommandReceived

当输入流收到 SCTE35 命令时,系统会生成 scte35CommandReceived 日志。scte35CommandReceived 日志的严重级别为 INFO

以下是 scte35CommandReceived 日志的示例:

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    scte35CommandReceived: {
      spliceInfoSection: {
        ptsAdjustment: "123456789"
        spliceInsert: {
          availNum: 0
          availsExpected: 0
          breakDuration: null
          componentCount: 0
          components: [0]
          durationFlag: false
          out0fNetworkIndicator: true
          programSpliceFlag: true
          spliceEventCancelIndicator: false
          spliceEventId: 123456789
          spliceImmediateFlag: true
          spliceTime: null
          uniqueProgramId: 5
        }
      }
    }
    message: "Received inband SCTE35 command, eventID=123456789."
  }
  ...
  severity: "INFO"
  ...
}

streamingStateChange

当频道的流式传输状态发生变化时,系统会生成 streamingStateChange 日志。当渠道的新状态为 STREAMING_ERROR 时,streamingStateChange 日志的严重级别为 ERROR。否则,streamingStateChange 日志的严重级别为 INFO

以下是 streamingStateChange 日志的示例,其中先前状态为 STREAMING_ERROR,新状态为 STREAMING

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    message: "streaming state of channel "CHANNEL_ID" changes from "STREAMING_ERROR" to "STREAMING""
    streamingStateChange: {
      newState: "STREAMING"
      previousState: "STREAMING_ERROR"
      ...
    type: "livestream.googleapis.com/Channel"
  }
  severity: "INFO"
  ...
}

您可以在日志浏览器查询字段中添加其他命令,以缩小显示的日志的范围。

添加以下命令以显示新状态为 STREAMING 的所有 streamingStateChange 日志:

jsonPayload.streamingStateChange.newState="STREAMING"

添加以下命令以仅显示 streamingStateChange 日志:

jsonPayload.streamingStateChange.newState:*

streamingError

当频道遇到与流式传输相关的错误时,系统会生成 streamingError 日志。streamingError 日志的日志严重级别为 ERROR

以下是 streamingError 日志的示例,其中,Live Stream API 无权将输出文件上传到指定 Cloud Storage 存储桶:

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    message: "A live streaming encounters an error."
    streamingError: {
      error: {
        ...
        message: "Permission denied to access the Cloud Storage bucket "STORAGE_BUCKET_NAME""
  ...
  severity: "ERROR"
  ...
}

如果指定的 Cloud Storage 存储桶不存在,也可能会发生此错误。

如果 streamingError.message 显示消息 This is due to an internal error. If the error persists, please contact support team,请复制日志的内容并将其发送给支持团队进行问题排查。

inputAccept

当输入流成功连接到 Live Stream API 输入端点时,系统会生成 inputAccept 日志。inputAccept 日志的严重级别为 INFO

inputAccept 日志中的 inputStreamProperty 字段包含有关输入流的视频子流和音频子流的以下信息:

视频流
  • index
  • 编解码器
  • 帧速率
  • 分辨率
音频流
  • index
  • 频道数
  • 频道布局
  • 编解码器信息

您可以使用 inputAccept 日志来验证输入流的格式和接受状态:

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    inputAccept: {
      inputAttachment: "input-primary"
      inputStreamProperty: {
        audioStreams: [
          0: {
            audioFormat: {
              channelCount: 2
              channelLayout: [
                0: "fl"
                1: "fr"
              ]
              codec: "aac"
            }
            index: 1
          }
        ]
        videoStreams: [
          0: {
            videoFormat: {
              codec: "h264"
              frameRate: 60
              heightPixels: 720
              widthPixels: 1280
      ...
      streamId: "STREAM_ID"
    }
    message: "Input stream "STREAM_ID" is accepted by channel "CHANNEL_ID" for input attachment "input-primary""
  }
  ...
  severity: "INFO"
  ...
}

在日志浏览器查询字段中添加以下命令,以仅显示特定流的 inputAccept 日志:

jsonPayload.inputAccept.streamId="STREAM_ID"

其中 STREAM_ID输入端点 URI 中包含的数据流的唯一标识符。

inputError

当 Live Stream API 拒绝输入流时,系统会生成 inputError 日志。inputError 日志的严重级别为 ERROR

以下是 inputError 日志的示例,其中输入流已发送到尚未开始的频道:

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    inputError: {
      error: {
        ...
        message: "The channel has not been started yet"
      }
      streamId: "STREAM_ID"
  ...
  severity: "ERROR"
  ...
}

以下是 inputError 日志的示例,其中重复的输入流被发送到已在流式传输的频道:

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    inputError: {
      error: {
        code: 9
        message: "input stream "STREAM_ID" has been accepted. Please verify if another input stream has been streaming to the same endpoint."
      }
      streamId: "STREAM_ID"
  ...
  severity: "ERROR"
  ...
}

在日志浏览器查询字段中添加以下命令,以仅显示特定流的 inputError 日志:

jsonPayload.inputError.streamId="STREAM_ID"

其中 STREAM_ID输入端点 URI 中包含的数据流的唯一标识符。

inputDisconnect

当输入流与 Live Stream API 断开连接时,系统会生成 inputDisconnect 日志。您可以使用 inputDisconnect 日志检查是否存在意外的直播断开连接。inputDisconnect 日志的严重级别为 INFO

以下是 inputDisconnect 日志的示例:

{
  jsonPayload: {
    @type: "type.googleapis.com/google.cloud.video.livestream.logging.v1.ChannelActivity"
    inputDisconnect: {
      inputAttachment: "input-primary"
      streamId: "STREAM_ID"
    }
    message: "Input stream "STREAM_ID" is disconnected by channel "CHANNEL_ID" for input attachment "input-primary""
  ...
  severity: "INFO"
  ...
}