I implemented a custom WebSocketAppender for log4j. Log messages were escaped using String.escapeHtml4, newlines were replaced with <br>.
Depending on the log level, messages where printed in bold (WARNING) or in red (ERROR or FATAL).
Events that were considered a problem that needs the user's attention were explicitly stored in a collection, and written to the websocket at the end when the program was done.