Add method MsgPastel to MelonLogger #738
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.
Adds a new method to MelonLogger called
MsgPastel
. The name might not make it really clear, but when I was developing a plugin I've come across an issue where the ANSI colors were also written in log files, making the logs less readable. To fix this, I've created a new method for writing messages that uses Regex to remove ANSI from logs. It's the same asMsg
with the exception that before writing to file, it runs the following regex:(\x1B|\e|\033)\[(.*?)m
to replace all matches with nothing. I'm not quite sure if the\x1B|\e|\033
needs to be there or only one of escape characters, but to be safe I added all of them. Depending on the device running MelonLoader, Regex could slow down the process of logging (from what I have tested, it was ~0.1/0.2 ms on a browser regex tester, but while running ML with regex checking all messages, it looked like there was practically no delay. But I have a pretty good computer so I'm not sure how that would work on slower computers), that's why it's made into a separate method.I've tested it with a plugin I'm working on that has a lot of ANSI colors and it seems to work well