diff --git a/internal/types/event/events.go b/internal/types/event/events.go index fd41b804..e16ed9ab 100644 --- a/internal/types/event/events.go +++ b/internal/types/event/events.go @@ -3,6 +3,7 @@ package event const ( SYSTEM_INIT = "system/init" SYSTEM_ADMIN = "system/admin" + SYSTEM_LOGS = "system/logs" SYSTEM_DISCONNECT = "system/disconnect" ) diff --git a/internal/types/message/messages.go b/internal/types/message/messages.go index 0649dd7d..06d63d1c 100644 --- a/internal/types/message/messages.go +++ b/internal/types/message/messages.go @@ -29,6 +29,14 @@ type SystemAdmin struct { BroadcastStatus BroadcastStatus `json:"broadcast_status"` } +type SystemLogs = []SystemLog + +type SystemLog struct { + Level string `json:"level"` + Fields map[string]string `json:"fields"` + Message string `json:"message"` +} + type SystemDisconnect struct { Message string `json:"message"` } diff --git a/internal/websocket/handler/handler.go b/internal/websocket/handler/handler.go index 2f3b5b28..b112cfb0 100644 --- a/internal/websocket/handler/handler.go +++ b/internal/websocket/handler/handler.go @@ -41,6 +41,13 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM var err error switch data.Event { + // System Events + case event.SYSTEM_LOGS: + payload := &message.SystemLogs{} + err = utils.Unmarshal(payload, data.Payload, func() error { + return h.systemLogs(session, payload) + }) + // Signal Events case event.SIGNAL_REQUEST: payload := &message.SignalVideo{} diff --git a/internal/websocket/handler/system.go b/internal/websocket/handler/system.go index 6052e079..59f72396 100644 --- a/internal/websocket/handler/system.go +++ b/internal/websocket/handler/system.go @@ -3,6 +3,8 @@ package handler import ( "errors" + "github.com/rs/zerolog" + "demodesk/neko/internal/types" "demodesk/neko/internal/types/event" "demodesk/neko/internal/types/message" @@ -80,3 +82,17 @@ func (h *MessageHandlerCtx) systemAdmin(session types.Session) error { return nil } + +func (h *MessageHandlerCtx) systemLogs(session types.Session, payload *message.SystemLogs) error { + for _, log := range *payload { + level, _ := zerolog.ParseLevel(log.Level) + + h.logger.WithLevel(level). + Fields(log.Fields). + Str("session_id", session.ID()). + Str("service", "frontend"). + Msg(log.Message) + } + + return nil +}