ueberdosis / hocuspocus

The CRDT Yjs WebSocket backend for conflict-free real-time collaboration in your app.
https://tiptap.dev/docs/hocuspocus/introduction
MIT License
1.21k stars 117 forks source link

Support logging request/socket information in custom Logger.log function #761

Open mortenson opened 9 months ago

mortenson commented 9 months ago

The problem I am facing When using a custom Logger.log function, all you get passed to you is the message as a string. It'd be nice if you were also passed as much information about the current socket/request as possible, so that you could log the client IP address, user agent, and other information common in more traditional HTTP logs.

The solution I would like Since changing the signature of LoggerConfiguration.log would probably break backwards compatibility, maybe either:

  1. A new LoggerConfiguration property like logFormat, which has more parameters including request/socket information and returns a string. Beyond adding request information, this seems generically useful for doing something like structured logging (JSON instead of having the timestamp in the log message) as well.
  2. More request/socket information passed to hooks - I tried adding logging in onAuthenticate but was not able to determine the request/socket IP address from onAuthenticatePayload.

Alternatives I have considered Making my own Logger extension, which would be OK but I'm not sure how to get the client IP address in hooks like onAuthenticatePayload.

Additional context At a high level I'm trying to add enough logging to the hocuspocus to make debugging security incidents feasible, which at a minimum would need the IP address of the current connection (for log messages where that is relevant).

mortenson commented 9 months ago

Note that if hocuspocus is behind a proxy, requestHeaders is probably sufficient (although you'll still need a completely custom logger, so the logFormat idea I think is still OK).