Send Message to console

How exactly do you go about sending text to the console from locations in a plugin that do not have a src ( other methods instead of command classes ). Need to send updates to console but can’t figure out how.

Logger should work

A constructor with Logger in it should would

You can also use game.getServer().getConsole() to get an instance of ConsoleSource where you can send messages.

2 Likes

Think carefully about whether you are trying to log a message, or have a delayed response to a commandsource.

If what you are doing is in response to a commandsources action, even if run from a scheduled task later on, you should keep a reference to that commandsource to send the message to from where ever you can get it from.

For example, a command might be issued to record and take an average ticks per second, and report every minute for the next 5 minutes.

This command may be sent via RCON, or another external commandsource that isn’t the console.

If you output your log, it may get missed, or not even output to the console depending on the logger settings.

If you send it straight to the console, the external commandsource may not receive the response it needed.

If you keep the reference to the commandsource, you can successfully send the message to whatever sent the command.

Loggers are for error logging, and plugin state reporting. Sending to the console is for notifying the root console of something that it should know. e.g. anti-cheat alerts or more, (but this might be better sent to all places with a permission)

3 Likes