TerminalConsoleAppender was never meant to be Minecraft-specific. It works just fine for other uses as well. The only Minecraft-specific code that it contains is the MinecraftFormattingConverter that is used to translate legacy color codes (§c etc) to ANSI color codes. I put that here because that was convenient back then when I needed the same code on multiple platforms.
But now legacy formatting codes have been deprecated for a long time, and there is no standard representation of newer features like RGB colors anymore. At this point, it seems easier if the projects that need it (and perhaps even want modern features like RGB support) make a copy of MinecraftFormattingConverter and change it to their needs. For example, Paper has made such a copy in PaperMC/Paper#5205.
As additional inspiration in case someone wants to implement this properly I will briefly describe a completely other, but potentially much cleaner approach that avoids legacy color codes entirely. I never found time to implement it, but I think it should work.
In particular, Log4j2 has the Message interface that can be passed to all log calls instead of a raw String. The idea would be to implement a custom Message class to retain all the properties of a text component (colors, hover events, ...), without having to serialize it into a raw string. Instead of logger.info(component.toLegacy()) you might use logger.info(new ComponentMessage(component)).
Then there is a sub-interface called MultiformatMessage, which can render itself differently based on the output it is appended to. So instead of having to strip color codes to log to a file, we can avoid generating them in the first place!
Something like this could be implemented once for a chat component API like adventure and then shared between projects that make use of adventure.
@zml2008 I believe we discussed this at some point? Did you ever finish implementing it? (I hope it was you, can't remember exactly and also can't find the chat log anymore. :D)
TerminalConsoleAppender was never meant to be Minecraft-specific. It works just fine for other uses as well. The only Minecraft-specific code that it contains is the
MinecraftFormattingConverterthat is used to translate legacy color codes (§cetc) to ANSI color codes. I put that here because that was convenient back then when I needed the same code on multiple platforms.But now legacy formatting codes have been deprecated for a long time, and there is no standard representation of newer features like RGB colors anymore. At this point, it seems easier if the projects that need it (and perhaps even want modern features like RGB support) make a copy of
MinecraftFormattingConverterand change it to their needs. For example, Paper has made such a copy in PaperMC/Paper#5205.As additional inspiration in case someone wants to implement this properly I will briefly describe a completely other, but potentially much cleaner approach that avoids legacy color codes entirely. I never found time to implement it, but I think it should work.
Something like this could be implemented once for a chat component API like adventure and then shared between projects that make use of adventure.
@zml2008 I believe we discussed this at some point? Did you ever finish implementing it? (I hope it was you, can't remember exactly and also can't find the chat log anymore. :D)