#1.19.2 chat logger

1 messages · Page 1 of 1 (latest)

winged hull
#

check ur minecraft logs. I'

#

m sure all messages u sent are logged

smoky marsh
smoky marsh
#

or give me any tips on how I could start out to achieve something like this, it would be greatly appreciated
@thick hull
step 1 a) well you'd want to first check if the fabric API has anything to make grabbing chat messages easier - ie if it has some sort of chat message Event that you could "subscribe" to (a thing that sets up code that you've written to run any time there is a chat message, and it gives your code the contents of that chat message)

step 1 b i) if there isn't a chat message event or related, then you'll have to do some looking into decompiled minecraft code (also done within IntelliJ) and find a section that deals with chat messages (and be careful about which code runs on the server, client, or both!)

step 1 b ii) once you find a decent spot in minecraft's code that deals with chat messages, you'll need to figure out how to make a mixin to inject your own code at that point, preferably grabbing the chat message as a String (or if you need to, convert it to a String)

- then once you have your chat message as a String, you log it to a file. I guess there'd be 2 ways to do that:

smoky marsh
#

step 2 a) find a library to do most of the work for you. There's lots of logging libraries, and minecraft already includes SLF4J (I'm 99% sure that's the one that mojang replaced Log4J with, right?). Then there should be a way to setup a new logger instance with a custom file location (use google/ask in the mod dev channels).
Then you just add that final logging step to whichever code gets your chat message as a String from step 1. (I guess that last bit might look like: MyMod.getChatLogger().info("[chat] " + timeStamp + " " + playerName + ": " + chatMessage);, but your code could look different to do the same thing)

step 2 b) If setting up whatever logging library to use a custom log file is too much of a hassle, you could instead do it manually by creating a text file, then opening it and appending the chat messages.

But manually dealing with files is more involved than you might think. You gotta check if the directory exists and create it if not. You gotta make sure the file doesn't get corrupted* if the server crashes (*well, I mean file contents being missing from the past however long). You might want to make a new file for each day and name it with the date (aka "log rotation"), but you also need to account for if the client/server is start/stopped multiple times per day. You might want to compress the log files or delete old ones automatically to save space. etc. etc. So basically it'd be a good learning experience, but I really recommend just trying to get some logging library to do what you want instead.

#

so yeah, that'd be the basic steps. And if you need any help for any of those steps, then use the mod dev channels here or google

glad socket
#

Fapi in fact has a message event you can use

#

It only fires when receiving player sent messages, and you can easily check who sent it, so that might be perfect for your use case

pulsar coyote
glad socket
faint marsh
#

Can log chat messages for restoring them back into the chat in future Minecraft sessions

winged hull
#

is 1.19.4 fine?

winged hull
#

Usage

/h99chatlog start [<filePath>] <options>
/h99chatlog stop

if options is empty it will use default option.
default options means

  1. Uses previously used options
  2. if there's no options as specified in 1, use "a"

Options (case insensitive) can be combined together.

s - sent messages
a - everything in chat window
r - received messages
#

100% client-sided