/src/main/java/me/taahanis/projectalpha/util/AlphaLog.java

https://bitbucket.org/thatonekid/projectalpha · Java · 94 lines · 63 code · 22 blank · 9 comment · 7 complexity · 55f2fdd5413727a2ec31041c3b4d76ab MD5 · raw file

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