Support logging request/socket information in custom Logger.log function
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:
- A new
LoggerConfigurationproperty likelogFormat, 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. - More request/socket information passed to hooks - I tried adding logging in
onAuthenticatebut was not able to determine the request/socket IP address fromonAuthenticatePayload.
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).
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).