/src/main/java/me/thatonekid/mskitpvpshop/ShopLog.java

https://bitbucket.org/thatonekid/ms-kitpvpshop · Java · 86 lines · 63 code · 19 blank · 4 comment · 7 complexity · e48cd229572748f7de7bb05311e650b6 MD5 · raw file

  1. package me.thatonekid.mskitpvpshop;
  2. import java.util.logging.Level;
  3. import java.util.logging.Logger;
  4. public class ShopLog {
  5. private static final Logger FALLBACK_LOGGER = Logger.getLogger("Minecraft-Server");
  6. private static Logger serverLogger = null;
  7. private static Logger pluginLogger = null;
  8. private ShopLog() {
  9. throw new AssertionError();
  10. }
  11. // Level.INFO:
  12. public static void info(String message) {
  13. info(message, false);
  14. }
  15. public static void info(String message, Boolean raw) {
  16. log(Level.INFO, message, raw);
  17. }
  18. public static void info(Throwable ex) {
  19. log(Level.INFO, ex);
  20. }
  21. // Level.WARNING:
  22. public static void warning(String message) {
  23. warning(message, false);
  24. }
  25. public static void warning(String message, Boolean raw) {
  26. log(Level.WARNING, message, raw);
  27. }
  28. public static void warning(Throwable ex) {
  29. log(Level.WARNING, ex);
  30. }
  31. // Level.SEVERE:
  32. public static void severe(String message) {
  33. severe(message, false);
  34. }
  35. public static void severe(String message, Boolean raw) {
  36. log(Level.SEVERE, message, raw);
  37. }
  38. public static void severe(Throwable ex) {
  39. log(Level.SEVERE, ex);
  40. }
  41. // Utility
  42. private static void log(Level level, String message, boolean raw) {
  43. getLogger(raw).log(level, message);
  44. }
  45. private static void log(Level level, Throwable throwable) {
  46. getLogger(false).log(level, null, throwable);
  47. }
  48. public static void setServerLogger(Logger logger) {
  49. serverLogger = logger;
  50. }
  51. public static void setPluginLogger(Logger logger) {
  52. pluginLogger = logger;
  53. }
  54. private static Logger getLogger(boolean raw) {
  55. if (raw || pluginLogger == null) {
  56. return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
  57. } else {
  58. return pluginLogger;
  59. }
  60. }
  61. public static Logger getPluginLogger() {
  62. return (pluginLogger != null ? pluginLogger : FALLBACK_LOGGER);
  63. }
  64. public static Logger getServerLogger() {
  65. return (serverLogger != null ? serverLogger : FALLBACK_LOGGER);
  66. }
  67. }