From 20585545245e6c14837c8a2a6f381875ac6a7fd0 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Fri, 1 Jul 2022 18:39:39 +0200 Subject: [PATCH] Allow to configure SRT logging --- README.md | 8 +++++++- app/api/api.go | 15 +++++++++------ config/config.go | 8 ++++++++ docs/docs.go | 46 ++++++++++++++++++++++++++++++++++++++++++++-- docs/swagger.json | 46 ++++++++++++++++++++++++++++++++++++++++++++-- docs/swagger.yaml | 31 +++++++++++++++++++++++++++++-- 6 files changed, 141 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 725fd70e..295fcaa4 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ The currently known environment variables (but not all will be respected) are: | CORE_SRT_ADDRESS | `:6000` | SRT server listen address. | | CORE_SRT_PASSPHRASE | (not set) | SRT passphrase. | | CORE_SRT_TOKEN | (not set) | SRT token for publishing and playing. The token is the value of the URL query parameter `token`. | +| CORE_SRT_LOG_ENABLE | `false` | Enable SRT server logging. | +| CORE_SRT_LOG_TOPICS | (not set) | List topics to log from SRT server. See https://github.com/datarhei/gosrt#logging. | | CORE_FFMPEG_BINARY | `ffmpeg` | Path to FFmpeg binary. | | CORE_FFMPEG_MAXPROCESSES | `0` | Max. allowed simultaneously running FFmpeg instances. Any value <= 0 means unlimited. | | CORE_FFMPEG_ACCESS_INPUT_ALLOW | (not set) | List of pattern for allowed input URI (space-separated), leave emtpy to allow any. | @@ -262,7 +264,11 @@ All other values will be filled with default values and persisted on disk. The e "enable": false, "address": ":6000", "passphrase": "", - "token": "" + "token": "", + "log": { + "enable": false, + "topics": [], + } }, "ffmpeg": { "binary": "ffmpeg", diff --git a/app/api/api.go b/app/api/api.go index 548e92ce..8b4137cf 100644 --- a/app/api/api.go +++ b/app/api/api.go @@ -696,12 +696,15 @@ func (a *api) start() error { if cfg.SRT.Enable { config := srt.Config{ - Addr: cfg.SRT.Address, - Passphrase: cfg.SRT.Passphrase, - Token: cfg.SRT.Token, - Logger: a.log.logger.core.WithComponent("SRT").WithField("address", cfg.SRT.Address), - Collector: a.sessions.Collector("srt"), - SRTLogTopics: []string{"listen", "handshake", "connection"}, + Addr: cfg.SRT.Address, + Passphrase: cfg.SRT.Passphrase, + Token: cfg.SRT.Token, + Logger: a.log.logger.core.WithComponent("SRT").WithField("address", cfg.SRT.Address), + Collector: a.sessions.Collector("srt"), + } + + if cfg.SRT.Log.Enable { + config.SRTLogTopics = cfg.SRT.Log.Topics } srtserver, err := srt.New(config) diff --git a/config/config.go b/config/config.go index d20342f5..d87b3cfc 100644 --- a/config/config.go +++ b/config/config.go @@ -140,6 +140,10 @@ type Data struct { Address string `json:"address"` Passphrase string `json:"passphrase"` Token string `json:"token"` + Log struct { + Enable bool `json:"enable"` + Topics []string `json:"topics"` + } `json:"log"` } `json:"srt"` FFmpeg struct { Binary string `json:"binary"` @@ -262,6 +266,8 @@ func NewConfigFrom(d *Config) *Config { data.Sessions.IPIgnoreList = copyStringSlice(d.Sessions.IPIgnoreList) + data.SRT.Log.Topics = copyStringSlice(d.SRT.Log.Topics) + data.Router.BlockedPrefixes = copyStringSlice(d.Router.BlockedPrefixes) data.Router.Routes = copyStringMap(d.Router.Routes) @@ -351,6 +357,8 @@ func (d *Config) init() { d.val(newAddressValue(&d.SRT.Address, ":6000"), "srt.address", "CORE_SRT_ADDRESS", nil, "SRT server listen address", false, false) d.val(newStringValue(&d.SRT.Passphrase, ""), "srt.passphrase", "CORE_SRT_PASSPHRASE", nil, "SRT encryption passphrase", false, true) d.val(newStringValue(&d.SRT.Token, ""), "srt.token", "CORE_SRT_TOKEN", nil, "SRT token for publishing and playing", false, true) + d.val(newBoolValue(&d.SRT.Log.Enable, false), "srt.log.enable", "CORE_SRT_LOG_ENABLE", nil, "Enable SRT server logging", false, false) + d.val(newStringListValue(&d.SRT.Log.Topics, []string{}, ","), "srt.log.topics", "CORE_SRT_LOG_TOPICS", nil, "List of topics to log", false, false) // FFmpeg d.val(newExecValue(&d.FFmpeg.Binary, "ffmpeg"), "ffmpeg.binary", "CORE_FFMPEG_BINARY", nil, "Path to ffmpeg binary", true, false) diff --git a/docs/docs.go b/docs/docs.go index 1900e9b6..119fd7e6 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2675,6 +2675,20 @@ const docTemplate = `{ "enable": { "type": "boolean" }, + "log": { + "type": "object", + "properties": { + "enable": { + "type": "boolean" + }, + "topics": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "passphrase": { "type": "string" }, @@ -3504,7 +3518,7 @@ const docTemplate = `{ "additionalProperties": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/api.SRTLog" } } }, @@ -3533,7 +3547,7 @@ const docTemplate = `{ "additionalProperties": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/api.SRTLog" } } }, @@ -3542,6 +3556,20 @@ const docTemplate = `{ } } }, + "api.SRTLog": { + "type": "object", + "properties": { + "msg": { + "type": "array", + "items": { + "type": "string" + } + }, + "ts": { + "type": "integer" + } + } + }, "api.SRTStatistics": { "type": "object", "properties": { @@ -4241,6 +4269,20 @@ const docTemplate = `{ "enable": { "type": "boolean" }, + "log": { + "type": "object", + "properties": { + "enable": { + "type": "boolean" + }, + "topics": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "passphrase": { "type": "string" }, diff --git a/docs/swagger.json b/docs/swagger.json index 9c47e21e..cc739a14 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2667,6 +2667,20 @@ "enable": { "type": "boolean" }, + "log": { + "type": "object", + "properties": { + "enable": { + "type": "boolean" + }, + "topics": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "passphrase": { "type": "string" }, @@ -3496,7 +3510,7 @@ "additionalProperties": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/api.SRTLog" } } }, @@ -3525,7 +3539,7 @@ "additionalProperties": { "type": "array", "items": { - "type": "string" + "$ref": "#/definitions/api.SRTLog" } } }, @@ -3534,6 +3548,20 @@ } } }, + "api.SRTLog": { + "type": "object", + "properties": { + "msg": { + "type": "array", + "items": { + "type": "string" + } + }, + "ts": { + "type": "integer" + } + } + }, "api.SRTStatistics": { "type": "object", "properties": { @@ -4233,6 +4261,20 @@ "enable": { "type": "boolean" }, + "log": { + "type": "object", + "properties": { + "enable": { + "type": "boolean" + }, + "topics": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "passphrase": { "type": "string" }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index f6a9153b..9374d7d8 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -307,6 +307,15 @@ definitions: type: string enable: type: boolean + log: + properties: + enable: + type: boolean + topics: + items: + type: string + type: array + type: object passphrase: type: string token: @@ -854,7 +863,7 @@ definitions: log: additionalProperties: items: - type: string + $ref: '#/definitions/api.SRTLog' type: array type: object publisher: @@ -873,12 +882,21 @@ definitions: log: additionalProperties: items: - type: string + $ref: '#/definitions/api.SRTLog' type: array type: object stats: $ref: '#/definitions/api.SRTStatistics' type: object + api.SRTLog: + properties: + msg: + items: + type: string + type: array + ts: + type: integer + type: object api.SRTStatistics: properties: avail_recv_buf_bytes: @@ -1392,6 +1410,15 @@ definitions: type: string enable: type: boolean + log: + properties: + enable: + type: boolean + topics: + items: + type: string + type: array + type: object passphrase: type: string token: