mirror of
https://github.com/Glimesh/broadcast-box.git
synced 2026-07-04 15:07:53 +00:00
Move session logs to DEBUG and add LOGGING_LEVEL env var
Demote session manager, WHIP and WHEP per-call log lines from Info to Debug so they don't spam the default Info output. Add a LOGGING_LEVEL environment variable (DEBUG/INFO/WARN/ERROR, default INFO) to control the minimum slog level.
This commit is contained in:
committed by
Sean DuBois
parent
a7771acfd9
commit
f11c7d6179
@@ -42,3 +42,8 @@
|
||||
# DEBUG_INCOMING_API_REQUEST=TRUE
|
||||
# DEBUG_PRINT_ANSWER=TRUE
|
||||
# DEBUG_PRINT_OFFER=TRUE
|
||||
|
||||
# ################
|
||||
# LOGGING
|
||||
# ################
|
||||
# LOGGING_LEVEL=INFO
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
# LOGGING
|
||||
# ################
|
||||
# LOGGING_ENABLED=TRUE
|
||||
# LOGGING_LEVEL=INFO
|
||||
# LOGGING_DIRECTORY=logs
|
||||
# LOGGING_SINGLEFILE=FALSE
|
||||
# LOGGING_NEW_FILE_ON_STARTUP=FALSE
|
||||
|
||||
@@ -43,6 +43,11 @@
|
||||
# DEBUG_PRINT_ANSWER=TRUE
|
||||
# DEBUG_PRINT_OFFER=TRUE
|
||||
|
||||
# ################
|
||||
# LOGGING
|
||||
# ################
|
||||
# LOGGING_LEVEL=INFO
|
||||
|
||||
# ################
|
||||
# CHAT
|
||||
# ################
|
||||
|
||||
@@ -305,6 +305,7 @@ These values are parsed by the Go backend and applied to WHIP/WHEP `PeerConnecti
|
||||
| Variable | Description |
|
||||
| ----------------------------- | --------------------------------------------------------------------------------------------------------- |
|
||||
| `LOGGING_ENABLED` | Enables logging system. |
|
||||
| `LOGGING_LEVEL` | Minimum slog level: `DEBUG`, `INFO`, `WARN`, or `ERROR`. Defaults to `INFO`. |
|
||||
| `LOGGING_DIRECTORY` | Directory to store log files. |
|
||||
| `LOGGING_SINGLEFILE` | Logs everything into a single file called 'log'. Default is log files are stamped with current date. |
|
||||
| `LOGGING_NEW_FILE_ON_STARTUP` | Creates a new log file on each startup. Either a new 'log' file, or replaces the current dates log file. |
|
||||
|
||||
@@ -20,6 +20,8 @@ var (
|
||||
)
|
||||
|
||||
func SetupLogger() {
|
||||
slog.SetLogLoggerLevel(parseLogLevel())
|
||||
|
||||
if strings.EqualFold(os.Getenv(loggingEnabled), "false") {
|
||||
return
|
||||
}
|
||||
@@ -28,6 +30,19 @@ func SetupLogger() {
|
||||
startLogRotation()
|
||||
}
|
||||
|
||||
func parseLogLevel() slog.Level {
|
||||
switch strings.ToUpper(os.Getenv(loggingLevel)) {
|
||||
case "DEBUG":
|
||||
return slog.LevelDebug
|
||||
case "WARN":
|
||||
return slog.LevelWarn
|
||||
case "ERROR":
|
||||
return slog.LevelError
|
||||
default:
|
||||
return slog.LevelInfo
|
||||
}
|
||||
}
|
||||
|
||||
func setupLoggerForDate(date string) {
|
||||
logFile, err := getLogFileWriter()
|
||||
if err != nil {
|
||||
|
||||
@@ -56,6 +56,7 @@ const (
|
||||
|
||||
// LOGGING
|
||||
loggingEnabled = "LOGGING_ENABLED"
|
||||
loggingLevel = "LOGGING_LEVEL"
|
||||
loggingDirectory = "LOGGING_DIRECTORY"
|
||||
loggingSingleFile = "LOGGING_SINGLEFILE"
|
||||
loggingNewFileOnStartup = "LOGGING_NEW_FILE_ON_STARTUP"
|
||||
|
||||
@@ -12,14 +12,14 @@ import (
|
||||
|
||||
// Prepare the WHIP Session Manager
|
||||
func (m *SessionManager) Setup() {
|
||||
slog.Info("WHIPSessionManager.Setup")
|
||||
slog.Debug("WHIPSessionManager.Setup")
|
||||
|
||||
m.sessions = make(map[string]*session.Session)
|
||||
}
|
||||
|
||||
// Add new session
|
||||
func (m *SessionManager) addSession(profile authorization.PublicProfile) (s *session.Session, err error) {
|
||||
slog.Info("SessionManager.AddWHIPSession")
|
||||
slog.Debug("SessionManager.AddWHIPSession")
|
||||
|
||||
s = &session.Session{
|
||||
|
||||
@@ -32,7 +32,7 @@ func (m *SessionManager) addSession(profile authorization.PublicProfile) (s *ses
|
||||
ChatManager: m.ChatManager,
|
||||
}
|
||||
s.SetOnClose(func() {
|
||||
slog.Info("SessionManager.Session.Done")
|
||||
slog.Debug("SessionManager.Session.Done")
|
||||
m.sessionsLock.Lock()
|
||||
delete(m.sessions, profile.StreamKey)
|
||||
m.sessionsLock.Unlock()
|
||||
@@ -50,10 +50,10 @@ func (m *SessionManager) GetOrAddSession(profile authorization.PublicProfile, is
|
||||
session, ok := m.GetSessionByID(profile.StreamKey)
|
||||
|
||||
if !ok {
|
||||
slog.Info("SessionManager.GetOrAddStream: Adding", "streamKey", profile.StreamKey)
|
||||
slog.Debug("SessionManager.GetOrAddStream: Adding", "streamKey", profile.StreamKey)
|
||||
session, err = m.addSession(profile)
|
||||
} else if isWHIP {
|
||||
slog.Info("SessionManager.GetOrAddStream: Updating", "streamKey", profile.StreamKey)
|
||||
slog.Debug("SessionManager.GetOrAddStream: Updating", "streamKey", profile.StreamKey)
|
||||
session.UpdateStreamStatus(profile)
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ func (m *SessionManager) GetOrAddSession(profile authorization.PublicProfile, is
|
||||
|
||||
// Get Session by id
|
||||
func (m *SessionManager) GetSessionByID(streamKey string) (session *session.Session, foundSession bool) {
|
||||
slog.Info("SessionManager.GetSessionByID", "streamKey", streamKey)
|
||||
slog.Debug("SessionManager.GetSessionByID", "streamKey", streamKey)
|
||||
|
||||
m.sessionsLock.RLock()
|
||||
defer m.sessionsLock.RUnlock()
|
||||
@@ -73,7 +73,7 @@ func (m *SessionManager) GetSessionByID(streamKey string) (session *session.Sess
|
||||
|
||||
// Gets the current state of all sessions
|
||||
func (m *SessionManager) GetSessionStates(includePrivateStreams bool) (result []session.StreamSessionState) {
|
||||
slog.Info("SessionManager.GetSessionStates", "isAdmin", includePrivateStreams)
|
||||
slog.Debug("SessionManager.GetSessionStates", "isAdmin", includePrivateStreams)
|
||||
m.sessionsLock.RLock()
|
||||
copiedSessions := make(map[string]*session.Session)
|
||||
maps.Copy(copiedSessions, m.sessions)
|
||||
@@ -149,7 +149,7 @@ func (m *SessionManager) GetSessionStates(includePrivateStreams bool) (result []
|
||||
|
||||
// Update the provided session information
|
||||
func (m *SessionManager) UpdateProfile(profile *authorization.PersonalProfile) {
|
||||
slog.Info("WHIPSessionManager.UpdateProfile")
|
||||
slog.Debug("WHIPSessionManager.UpdateProfile")
|
||||
m.sessionsLock.RLock()
|
||||
whipSession, ok := m.sessions[profile.StreamKey]
|
||||
m.sessionsLock.RUnlock()
|
||||
|
||||
@@ -27,7 +27,7 @@ func (session *Session) SetOnClose(onClose func()) {
|
||||
|
||||
// Add WHEP viewer session
|
||||
func (s *Session) AddWHEP(whepSessionID string, peerConnection *webrtc.PeerConnection, audioTrack *codecs.TrackMultiCodec, videoTrack *codecs.TrackMultiCodec, videoRTCPSender *webrtc.RTPSender, pliSender func()) (err error) {
|
||||
slog.Info("WHIPSessionManager.WHIPSession.AddWHEPSession")
|
||||
slog.Debug("WHIPSessionManager.WHIPSession.AddWHEPSession")
|
||||
|
||||
whepSession := whep.CreateNewWHEP(
|
||||
whepSessionID,
|
||||
@@ -53,7 +53,7 @@ func (s *Session) AddWHEP(whepSessionID string, peerConnection *webrtc.PeerConne
|
||||
|
||||
// Add host
|
||||
func (s *Session) AddHost(peerConnection *webrtc.PeerConnection) (err error) {
|
||||
slog.Info("Session.AddHost")
|
||||
slog.Debug("Session.AddHost")
|
||||
|
||||
for {
|
||||
host := s.Host.Load()
|
||||
@@ -169,16 +169,16 @@ func (s *Session) Close() {
|
||||
// Returns true is no WHIP tracks are present, and no WHEP sessions are waiting for incoming streams
|
||||
func (s *Session) isEmpty() bool {
|
||||
if s.hasWHEPSessions() {
|
||||
slog.Info("Session.IsEmpty.HasWHEPSessions (false)", "streamKey", s.StreamKey)
|
||||
slog.Debug("Session.IsEmpty.HasWHEPSessions (false)", "streamKey", s.StreamKey)
|
||||
return false
|
||||
}
|
||||
|
||||
if s.isStreaming() {
|
||||
slog.Info("Session.IsEmpty.IsActive (false)", "streamKey", s.StreamKey)
|
||||
slog.Debug("Session.IsEmpty.IsActive (false)", "streamKey", s.StreamKey)
|
||||
return false
|
||||
}
|
||||
|
||||
slog.Info("Session.IsEmpty (true)", "streamKey", s.StreamKey)
|
||||
slog.Debug("Session.IsEmpty (true)", "streamKey", s.StreamKey)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -193,12 +193,12 @@ func (s *Session) isStreaming() bool {
|
||||
host.TracksLock.RLock()
|
||||
|
||||
if len(host.AudioTracks) != 0 {
|
||||
slog.Info("Session.IsActive.AudioTracks", "count", len(host.AudioTracks))
|
||||
slog.Debug("Session.IsActive.AudioTracks", "count", len(host.AudioTracks))
|
||||
host.TracksLock.RUnlock()
|
||||
return true
|
||||
}
|
||||
if len(host.VideoTracks) != 0 {
|
||||
slog.Info("Session.IsActive.VideoTracks", "count", len(host.VideoTracks))
|
||||
slog.Debug("Session.IsActive.VideoTracks", "count", len(host.VideoTracks))
|
||||
host.TracksLock.RUnlock()
|
||||
return true
|
||||
}
|
||||
@@ -209,7 +209,7 @@ func (s *Session) isStreaming() bool {
|
||||
|
||||
func (s *Session) hasWHEPSessions() bool {
|
||||
s.WHEPSessionsLock.RLock()
|
||||
slog.Info("Session.HasWHEPSessions", "count", len(s.WHEPSessions))
|
||||
slog.Debug("Session.HasWHEPSessions", "count", len(s.WHEPSessions))
|
||||
|
||||
if len(s.WHEPSessions) == 0 {
|
||||
s.WHEPSessionsLock.RUnlock()
|
||||
|
||||
@@ -19,7 +19,7 @@ func CreateNewWHEP(
|
||||
pliSender func(),
|
||||
chatManager *chat.Manager,
|
||||
) (w *WHEPSession) {
|
||||
slog.Info("WHEPSession.CreateNewWHEP", "whepSessionID", whepSessionID)
|
||||
slog.Debug("WHEPSession.CreateNewWHEP", "whepSessionID", whepSessionID)
|
||||
|
||||
w = &WHEPSession{
|
||||
SessionID: whepSessionID,
|
||||
@@ -45,16 +45,16 @@ func CreateNewWHEP(
|
||||
func (w *WHEPSession) Close() {
|
||||
// Close WHEP channels
|
||||
w.SessionClose.Do(func() {
|
||||
slog.Info("WHEPSession.Close")
|
||||
slog.Debug("WHEPSession.Close")
|
||||
w.IsSessionClosed.Store(true)
|
||||
|
||||
// Close PeerConnection
|
||||
slog.Info("WHEPSession.Close.PeerConnection.GracefulClose")
|
||||
slog.Debug("WHEPSession.Close.PeerConnection.GracefulClose")
|
||||
err := w.PeerConnection.Close()
|
||||
if err != nil {
|
||||
slog.Error("WHEPSession.Close.PeerConnection.Error", "err", err)
|
||||
}
|
||||
slog.Info("WHEPSession.Close.PeerConnection.GracefulClose.Completed")
|
||||
slog.Debug("WHEPSession.Close.PeerConnection.GracefulClose.Completed")
|
||||
|
||||
// Empty tracks
|
||||
w.AudioLock.Lock()
|
||||
@@ -109,7 +109,7 @@ func (w *WHEPSession) GetWHEPSessionStatus() (state SessionState) {
|
||||
|
||||
// Sets the requested audio layer for this WHEP session.
|
||||
func (w *WHEPSession) SetAudioLayer(encodingID string) {
|
||||
slog.Info("Setting Audio Layer")
|
||||
slog.Debug("Setting Audio Layer")
|
||||
w.AudioLayerCurrent.Store(encodingID)
|
||||
w.IsWaitingForKeyframe.Store(true)
|
||||
w.SendPLI()
|
||||
@@ -117,7 +117,7 @@ func (w *WHEPSession) SetAudioLayer(encodingID string) {
|
||||
|
||||
// Sets the requested video layer for this WHEP session.
|
||||
func (w *WHEPSession) SetVideoLayer(encodingID string) {
|
||||
slog.Info("Setting Video Layer")
|
||||
slog.Debug("Setting Video Layer")
|
||||
|
||||
w.VideoLock.Lock()
|
||||
w.VideoLayerCurrent.Store(encodingID)
|
||||
|
||||
Reference in New Issue
Block a user