本页面介绍了如何使用 Live Stream API 生成的平台日志,这些日志是
Cloud Logging的一部分。Live Stream API 使用 Logging API 服务名称
livestream.googleapis.com 记录与频道相关的活动。
准备工作
- 确保您拥有正确的 IAM 权限和角色,以便查看和 管理日志。
启用平台日志记录
默认情况下,Live Stream API 的 livestream.googleapis.com/channel_activities 平台日志处于停用状态。如需启用这些日志,您需要在创建或更新频道资源时指定严重级别。
如需启用日志,请将以下字段添加到
projects.locations.channels.create或
projects.locations.channels.patch方法的请求 JSON 正文中:
"logConfig": {
"logSeverity": "SEVERITY_LEVEL"
},
其中,SEVERITY_LEVEL 是以下值之一:
OFFDEBUGINFOWARNINGERROR
为频道选择日志严重级别后,系统只会记录严重级别高于或等于所选严重级别的平台日志。
例如,如果严重级别为 WARNING,则系统只会记录严重级别为 WARNING 和 ERROR 的日志。如果严重级别为 INFO,则系统会记录除 DEBUG 之外的所有严重级别的日志。
如需详细了解日志严重级别,请参阅 LogSeverity。
查看平台日志
如需查看平台日志,请按以下说明操作:
控制台
如需在 Google Cloud 控制台中查看平台日志,请执行以下操作:
导航到日志浏览器:
选择相应的 Google Cloud 项目。
在查询 字段中,输入以下查询命令:
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。
点击运行查询 。
如需详细了解 Logs Explorer,请参阅 Logs Explorer 概览和使用 Logs Explorer。
gcloud
gcloud 命令行工具提供了用于 Cloud Logging 的命令行界面。
如需查看项目的 channel_activities 日志,请运行以下命令:
gcloud logging read "logName:projects/PROJECT_ID/logs/livestream.googleapis.com%2Fchannel_activities" --project=PROJECT_ID
其中,PROJECT_ID 是项目的 ID。 Google Cloud
如需详细了解如何将 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。
系统只会处理 durationFlag、breakDuration、spliceTime 和 outOfNetworkIndicator。如果缺少 spliceTime,系统会立即执行 SCTE35 命令。所有其他字段都被视为空操作。
以下是 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
outOfNetworkIndicator: 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"
...
}
您可以在 Logs Explorer 查询 字段中添加其他命令,以缩小显示的日志范围。
添加以下命令可显示新状态为 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 字段包含以下有关输入流的视频和音频子流的信息:
| 视频流 |
|
| 音频流 |
|
您可以使用 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"
...
}
在 Logs Explorer 查询 字段中添加以下命令,可仅显示特定流的 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"
...
}
在 Logs Explorer 查询 字段中添加以下命令,可仅显示特定流的 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"
...
}