mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
receive frontend logs using WS.
This commit is contained in:
parent
83aa2dde41
commit
afc79ed847
@ -3,6 +3,7 @@ package event
|
|||||||
const (
|
const (
|
||||||
SYSTEM_INIT = "system/init"
|
SYSTEM_INIT = "system/init"
|
||||||
SYSTEM_ADMIN = "system/admin"
|
SYSTEM_ADMIN = "system/admin"
|
||||||
|
SYSTEM_LOGS = "system/logs"
|
||||||
SYSTEM_DISCONNECT = "system/disconnect"
|
SYSTEM_DISCONNECT = "system/disconnect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,6 +29,14 @@ type SystemAdmin struct {
|
|||||||
BroadcastStatus BroadcastStatus `json:"broadcast_status"`
|
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 {
|
type SystemDisconnect struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,13 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch data.Event {
|
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
|
// Signal Events
|
||||||
case event.SIGNAL_REQUEST:
|
case event.SIGNAL_REQUEST:
|
||||||
payload := &message.SignalVideo{}
|
payload := &message.SignalVideo{}
|
||||||
|
@ -3,6 +3,8 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
"demodesk/neko/internal/types/event"
|
"demodesk/neko/internal/types/event"
|
||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
@ -80,3 +82,17 @@ func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user