Forward logs to Discord #579
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.








Overview
This is a convenience replacement for the (broken/deactivated) Logviewer project.
It forwards all logs to a Discord channel, via webhooks.
Info/Error channel
The day to day routine will be that we want to be notified when an error/warning happened, but not for info logs. Therefore, we set up 2 channels with separate webhooks. One for errors, one for infos:
Now, users can mute one channel and keep notifications on for the other.
Security
Note that logs can contain sensitive information (for example when banning an user). Therefore, a new log marker
LogMarkers.SENSITIVEhas been added. Logs with that marker are not forwarded to Discord. All existing logs have been checked and adjusted. Looks something like this:Details
Queue
The implementation is relatively straightforward, but has some non trivial complexity. In a nutshell, it buffers all incoming logs in a
PriorityQueue(ordered on the timestamp to ensure correct log order). The queue has a max size of10_000logs and ideally is never hit in practice (this is to protect RAM, in case).The queue is then processed each 5 seconds with a
ScheduledExecutorService. The service then polls and sends a maximum of 10 logs in a batch request to Discord.Failures
If the request fails, the logs are put back into the queue. If a batch fails 3 times, it is discarded to not entirely block the whole mechanism forever.
Rate limitting
When we send too much, Discord hits us with rate limits (
429http status). When this happens, we extract the end of the limitation from theretry-afterheader and skip theScheduledExecutorServicecalls untilInstant.now()is after that time.Logging the logger
The whole system also has logging/error reporting itself. Its logs all have a
LogMarkers.NO_DISCORDthough, to prevent that it forwards its own logs - which could lead to a potential infinite loop of spawning logs in an erroneous scenario.Config
The config has been changed, add:
Checklist