Skip to content

Commit

Permalink
Include connection remote address in log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Thor77 committed Nov 26, 2019
1 parent 2dd7355 commit c60e1d8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,26 @@ func handleError(logger *log.Entry, conn *rtmp.Conn, err error) {
}

func publishHandler(conn *rtmp.Conn) {
log.Debugf("Handling request %s\n", conn.URL.RequestURI())
connLogger := log.WithField("remoteAddr", conn.NetConn().RemoteAddr().String())
connLogger.Debugf("Handling request %s\n", conn.URL.RequestURI())

// verify key
if config.Key != "" {
givenKey := conn.URL.Query().Get("key")
if givenKey != config.Key {
handleErrorString(log.WithField("givenKey", givenKey), conn, "Key mismatch, aborting request")
handleErrorString(connLogger.WithField("givenKey", givenKey), conn, "Key mismatch, aborting request")
return
}
}

// verify stream has a name
streamName := strings.ReplaceAll(conn.URL.Path, "/", "")
if streamName == "" {
handleErrorString(log.WithField("path", conn.URL.Path), conn, "Invalid stream name")
handleErrorString(connLogger.WithField("path", conn.URL.Path), conn, "Invalid stream name")
return
}

streamLogger := log.WithFields(log.Fields{"stream": streamName})
streamLogger := connLogger.WithFields(log.Fields{"stream": streamName})

streamLogger.Infoln("Client connected")

Expand Down

0 comments on commit c60e1d8

Please sign in to comment.