Solved Logging and onEnable

Discussion in 'Spigot Plugin Development' started by Remixful, Apr 24, 2017.

  1. Hello everyone.
    I am trying to understand how onEnable works with /reload. How do I use the logger in onEnable after /reload is used?
    I've tried several things I've seen other plugins use such as having a private Logger variable and assigning it to this.getLogger() onEnable, but logging still does not work then.

    Why does onLoad work great, but not onEnable?
    #1 Remixful, Apr 24, 2017
    Last edited: Apr 24, 2017
  2. What happens on a reload, the plugins are getting the stop command, after everything has stoppped, it starts everything again.
    It should log something if you use onenable and than Bukkit.getlogger().info("something");
    Can i see your code?
  3. Code (Text):

    public class main extends JavaPlugin implements Listener {

       public void onLoad() {
            String version = getDescription().getVersion();
            Bukkit.broadcastMessage(String.format("Version %s has loaded!", version));

        public void onEnable(){
            getLogger().info("Why doesn't this work on /reload?");
  4. There must be a problem with Multicraft console because it works locally.. I mean, the Multicraft console is displaying the info log on start but not when I /reload... Why...
  5. Choco


    1. Your class names should be UpperCamelCase (i.e. in this case, "Main"). Typically, the main classes of plugins are not titled, "Main", however, as it is not the entry point of the program.
    2. You do not need to print anything onEnable() or onDisable() at all. Bukkit does this for you
    3. You should have @Override annotations over your #onEnable() and #onLoad() methods because they are inherited from the super class, JavaPlugin
    4. Implementing Listener is pointless if the class does not contain any event methods
  6. Thank you for the tips, but this doesn't help me fix my problem. I cut off the events from my code since it's not related the issue at hand. I've also added @Override annotations now. And I'm pretty sure my naming convention preference has nothing to do with it either.

    I do need to log in onEnable() for when I catch errors and such when I'm creating/using a config.
  7. Mas


    Naming conventions aren't a "preference", it's how you are supposed to name things. Follow them, they're there for a reason.
    If you really need to log in onEnable and the Logger isn't working, just use System.out.println() and it should be fine.
    • Funny Funny x 1
  8. I've tried this, I think it's a problem with Multicraft like I said... I'm not sure how to fix it or what logger it is using.
  9. Code (Text):
    [16:32:42] [Server thread/INFO]: CONSOLE: Please note that this command is not supported and may cause issues when using some plugins.
    [16:32:42] [Server thread/INFO]: CONSOLE: If you encounter any issues please use the /stop command to restart your server.
    [16:32:42] [Server thread/INFO]: Server Ping Player Sample Count: 12
    [16:32:42] [Server thread/INFO]: Using 4 threads for Netty based IO
    [16:32:42] [Server thread/INFO]: Debug logging is disabled
    [16:32:42] [Server thread/INFO]: [WorldEditSelectionVisualizer] Disabling WorldEditSelectionVisualizer v1.4.5
    [16:32:42] [Server thread/INFO]: [WorldGuard] Disabling WorldGuard v6.1.3-SNAPSHOT;c904242
    [16:32:42] [Server thread/INFO]: [WorldGuard] Shutting down executor and waiting for any pending tasks...
    [16:32:42] [Server thread/INFO]: [Test] Disabling Test v1.0
    [16:32:42] [Server thread/INFO]: [Essentials] Disabling Essentials vTeamCity
    [16:32:42] [Server thread/INFO]: [Vault][Economy] Essentials Economy unhooked.
    [16:32:42] [Server thread/INFO]: [Vault] Disabling Vault v1.5.6-b49
    [16:32:42] [Server thread/INFO]: [WorldEdit] Disabling WorldEdit v6.1.5;4651611
    [16:32:42] [Server thread/INFO]: [NoteBlockAPI] Disabling NoteBlockAPI v1.1.5
    [16:32:42] [Server thread/INFO]: [NoteBlockAPI] Loading NoteBlockAPI v1.1.5
    [16:32:42] [Server thread/INFO]: [WorldEdit] Loading WorldEdit v6.1.5;4651611
    [16:32:42] [Server thread/INFO]: [Vault] Loading Vault v1.5.6-b49
    [16:32:42] [Server thread/INFO]: [Essentials] Loading Essentials vTeamCity
    [16:32:42] [Server thread/INFO]: [Test] Loading Test v1.0
    [16:32:42] [Server thread/INFO]: [WorldGuard] Loading WorldGuard v6.1.3-SNAPSHOT;c904242
    [16:32:42] [Server thread/INFO]: [WorldEditSelectionVisualizer] Loading WorldEditSelectionVisualizer v1.4.5
    [16:32:42] [Server thread/INFO]: [Vault] Enabling Vault v1.5.6-b49
    [16:32:42] [Server thread/INFO]: [Vault] [Economy] Essentials Economy found: Waiting
    [16:32:42] [Server thread/INFO]: [Vault] [Permission] SuperPermissions loaded as backup permission system.
    [16:32:42] [Server thread/INFO]: [Vault] Enabled Version 1.5.6-b49
    [16:32:42] [Server thread/INFO]: [NoteBlockAPI] Enabling NoteBlockAPI v1.1.5
    [16:32:42] [Server thread/INFO]: [WorldEdit] Enabling WorldEdit v6.1.5;4651611
    [16:32:42] [Server thread/INFO]: WEPIF: Using the Bukkit Permissions API.
    [16:32:42] [Server thread/INFO]: [WorldEdit] Using com.sk89q.worldedit.bukkit.adapter.impl.Spigot_v1_11_R1 as the Bukkit adapter
    [16:32:42] [Server thread/INFO]: [Essentials] Enabling Essentials vTeamCity
    [16:32:42] [Server thread/INFO]: Bukkit version format changed. Version not checked.
    [16:32:42] [Server thread/INFO]: git-Spigot-7d78b81-f9e0440 (MC: 1.11.2)
    [16:32:42] [Server thread/INFO]: 1.11.2-R0.1-SNAPSHOT
    [16:32:42] [Server thread/INFO]: Using locale en_US
    [16:32:42] [Server thread/INFO]: Using locale en_US
    [16:32:42] [Server thread/INFO]: [Vault][Economy] Essentials Economy hooked.
    [16:32:42] [Server thread/INFO]: Essentials: Using config file enhanced permissions.
    [16:32:42] [Server thread/INFO]: Permissions listed in as player-commands will be given to all users.
    [16:32:42] [Server thread/INFO]: [Test] Enabling Test v1.0
    [16:32:42] [Server thread/INFO]: [Test] Doesn't work
    [16:32:42] [Server thread/INFO]: [WorldGuard] Enabling WorldGuard v6.1.3-SNAPSHOT;c904242
    [16:32:42] [Server thread/INFO]: [WorldGuard] (main) TNT ignition is PERMITTED.
    [16:32:42] [Server thread/INFO]: [WorldGuard] (main) Lighters are PERMITTED.
    [16:32:42] [Server thread/INFO]: [WorldGuard] (main) Lava fire is blocked.
    [16:32:42] [Server thread/INFO]: [WorldGuard] (main) Fire spread is UNRESTRICTED.
    [16:32:42] [Server thread/INFO]: [WorldGuard] Loaded configuration for world 'main'
    [16:32:42] [Server thread/INFO]: [WorldGuard] Loading region data...
    I can clearly see it in latest.log when I reload. But it never shows in the server console on Multicraft.
  10. Essentially, each time /reload is done, it triggers the plugin to "reload" its self (disable, unload and load back in again).
    It's easy to do what you are doing: just use the getLogger()#info(String); place that in the onEnable and it will dispense the string to the console (aka run the System.out.println() pretty much) once the plugin has enabled

    if you are attempting to dispense certain text after a reload, then... unfortunately, I don't believe its possible to do that
  11. It does display the logs locally. I've tried to contact my server host but they haven't replied yet. I'm hopping this is something that can be fixed.

    I am not getting the skipped lines error though. (But that's Multicraft I believe)
  12. electronicboy

    IRC Staff

    Try renaming the plugin, panels love to do stupid stuff like filtering on specific terms, Test might be one of them ¯\_(ツ)_/¯
  13. My host raised the Multicraft rate limit from 30 to 50 now. It's fixed.