diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2020-04-15 09:24:56 +0100 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2020-04-15 09:24:56 +0100 |
| commit | d39a6d4084266c4fd500aecc5f256e9ce8948ded (patch) | |
| tree | 9d62fadb6b1848d9c29b4a1fdd081a12649f90fb /src | |
| parent | 1912d6a39306f7138ad30941fd62cc7ae19b08ed (diff) | |
Quests logger to allow configuration on how much Quests logs
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/QuestsLogger.java | 81 | ||||
| -rw-r--r-- | src/main/resources/config.yml | 4 |
2 files changed, 84 insertions, 1 deletions
diff --git a/src/main/java/com/leonardobishop/quests/QuestsLogger.java b/src/main/java/com/leonardobishop/quests/QuestsLogger.java new file mode 100644 index 00000000..212592c2 --- /dev/null +++ b/src/main/java/com/leonardobishop/quests/QuestsLogger.java @@ -0,0 +1,81 @@ +package com.leonardobishop.quests; + +public class QuestsLogger { + + private Quests plugin; + private LoggingLevel serverLoggingLevel; + + public QuestsLogger(Quests plugin, LoggingLevel serverLoggingLevel) { + this.plugin = plugin; + this.serverLoggingLevel = serverLoggingLevel; + } + + public LoggingLevel getServerLoggingLevel() { + return serverLoggingLevel; + } + + public void setServerLoggingLevel(LoggingLevel serverLoggingLevel) { + this.serverLoggingLevel = serverLoggingLevel; + } + + public void log(String str, LoggingLevel level) { + if (serverLoggingLevel.getNumericVerbosity() < level.getNumericVerbosity()) { + return; + } + switch (level) { + case DEBUG: + plugin.getLogger().info("Debug: " + str); + break; + case INFO: + plugin.getLogger().info(str); + break; + case ERROR: + plugin.getLogger().severe(str); + break; + case WARNING: + plugin.getLogger().warning(str); + break; + } + } + + public void debug(String str) { + log(str, LoggingLevel.DEBUG); + } + + public void info(String str) { + log(str, LoggingLevel.INFO); + } + + public void warning(String str) { + log(str, LoggingLevel.WARNING); + } + + public void severe(String str) { + log(str, LoggingLevel.ERROR); + } +} +enum LoggingLevel { + ERROR(0), + WARNING(1), + INFO(2), + DEBUG(3); + + private int numericVerbosity; + + LoggingLevel(int number) { + numericVerbosity = number; + } + + public int getNumericVerbosity() { + return numericVerbosity; + } + + static LoggingLevel fromNumber(int number) { + for (LoggingLevel level : LoggingLevel.values()) { + if (level.getNumericVerbosity() == number) { + return level; + } + } + return LoggingLevel.INFO; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ca22230d..150e8a55 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -135,7 +135,7 @@ options: quests-menu: "Quests" daily-quests: "Daily Quests" quest-cancel: "Cancel Quest" - # Show when quests register in console. Disable if you want less console spam at startup. + # Show when quests register in console - will only show if verbose-logging-level=2. Disable if you want less console spam at startup. show-quest-registrations: true # Hide quests which a player cannot start due to permissions. gui-hide-quests-nopermission: false @@ -143,6 +143,8 @@ options: gui-hide-categories-nopermission: false # Make it so players do not have to start quest themselves quest-autostart: false + # How much quests should log, 0 = errors only, 1 = warnings, 2 = info, 3 = debug + verbose-logging-level: 2 performance-tweaking: # The following are measured in server ticks, multiply SECONDS by 20 to get the number of ticks. quest-completer-poll-interval: 100 # how frequently Quests should check if quests have been completed (def=100 - 5 seconds) - increase this value if you are struggling with performance quest-autosave-interval: 12000 # how frequently online players data will be autosaved (def=12000 - 10 minutes) |
