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/main/java/com | |
| parent | 1912d6a39306f7138ad30941fd62cc7ae19b08ed (diff) | |
Quests logger to allow configuration on how much Quests logs
Diffstat (limited to 'src/main/java/com')
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/QuestsLogger.java | 81 |
1 files changed, 81 insertions, 0 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; + } +} |
