Logger
The API also includes an advanced logger for in-game and console logging.
Setup
First, you need to set up the logger in your main class by initializing it in the onEnable method.
class TestingPlugin : JavaPlugin() {
override fun onEnable() {
Logger.initialize("Your plugin name")
}
override fun onDisable() {
}
}
In-game logging
If you want to send an in-game log message, you can call the Logger.log method.
This will send a log to all players with a specific permission.
log(playerSuffix, sender, permission, message)
The playerSuffix is just some extra text added after the player's name, useful for things like showing what a player is looking at or clicked on. You can leave it blank if you don't need it.
Console logging
There are 6 methods you can call for console logging.
The basic ones are info, error, and warn.
These will send a colored message (if your console supports it) with the information you provide:
info(message)
error(message)
warn(message)
Example output:
[TestingPlugin] (info) Loading Testing plugin
If you use a database, you can also use the database logger methods. These work the same, except the plugin name includes "Database":
[TestingPlugin Database] (info) Connected to H2 database.
Methods:
infoDB(message)
errorDB(message)
warnDB(message)
You can also send a quick message straight to a Discord webhook with Logger.log(webhookURL, message). If you need something fancier like embeds, check out Discord webhooks.