mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-29 00:47:08 +02:00
websockets set max payload log size. (#42)
This commit is contained in:
parent
2ff47ac920
commit
43a649d2c4
2 changed files with 22 additions and 6 deletions
|
@ -23,6 +23,9 @@ const pingPeriod = 10 * time.Second
|
|||
// period for sending inactive cursor messages
|
||||
const inactiveCursorsPeriod = 750 * time.Millisecond
|
||||
|
||||
// maximum payload length for logging
|
||||
const maxPayloadLogLength = 10_000
|
||||
|
||||
// events that are not logged in debug mode
|
||||
var nologEvents = []string{
|
||||
// don't log twice
|
||||
|
@ -313,10 +316,15 @@ func (manager *WebSocketManagerCtx) handle(connection *websocket.Conn, peer type
|
|||
|
||||
// log events if not ignored
|
||||
if ok, _ := utils.ArrayIn(data.Event, nologEvents); !ok {
|
||||
payload := data.Payload
|
||||
if len(payload) > maxPayloadLogLength {
|
||||
payload = []byte("<truncated>")
|
||||
}
|
||||
|
||||
logger.Debug().
|
||||
Str("address", connection.RemoteAddr().String()).
|
||||
Str("event", data.Event).
|
||||
Str("payload", string(data.Payload)).
|
||||
Str("payload", string(payload)).
|
||||
Msg("received message from client")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue