Created
December 9, 2019 16:38
-
-
Save noudadrichem/819faa13c57a05fc8805c9b54b5de48f to your computer and use it in GitHub Desktop.
Java utility class to get Logs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// INTERFACE: | |
public interface ILogger { | |
public static void error(String msg, Object obj) { | |
System.out.println(msg + " " + obj.toString()); | |
} | |
public static void warning(String msg, Object obj) { | |
System.out.println(msg + " " + obj.toString()); | |
} | |
public static void info(String msg, Object obj) { | |
System.out.println(msg + " " + obj.toString()); | |
} | |
public static void error(String msg) { | |
System.out.println(msg); | |
} | |
public static void warning(String msg) { | |
System.out.println(msg); | |
} | |
public static void info(String msg) { | |
System.out.println(msg); | |
} | |
} | |
// CLASS: | |
public class Logger implements ILogger { | |
private static final String ERROR = "ERROR: "; | |
private static final String WARNING = "WARNING: "; | |
private static final String INFO = "INFO: "; | |
private static final String ANSI_RED = "\u001B[31m"; | |
private static final String ANSI_BLUE = "\u001B[34m"; | |
private static final String ANSI_YELLOW = "\u001B[33m"; | |
private static final String ANSI_RESET = "\u001B[0m"; | |
public static void error(String msg, Object obj) { | |
String message = ANSI_RED + ERROR + ANSI_RESET + msg; | |
log(message, obj); | |
} | |
public static void warning(String msg, Object obj) { | |
String message = ANSI_YELLOW + WARNING + ANSI_RESET + msg; | |
log(message, obj); | |
} | |
public static void info(String msg, Object obj) { | |
String message = ANSI_BLUE + INFO + ANSI_RESET + msg; | |
log(message, obj); | |
} | |
public static void error(String msg) { | |
error(msg, null); | |
} | |
public static void warning(String msg) { | |
warning(msg, null); | |
} | |
public static void info(String msg) { | |
info(msg, null); | |
} | |
private static void log(String msg, Object obj) { | |
if (obj != null) { | |
System.out.println(msg + " :: " + obj.toString()); | |
return; | |
} | |
System.out.println(msg); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment