Last active
March 24, 2020 04:59
-
-
Save haseebpvt/3817dbcd0fbc049f3fbec9da7c45308f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import java.text.SimpleDateFormat; | |
| import java.util.Date; | |
| import java.util.Locale; | |
| public class EasyLogger { | |
| private static StringBuilder sb; | |
| /** | |
| * A way to log all around application | |
| * @param str The text to log | |
| */ | |
| public static void log(String str) { | |
| if (sb == null) { | |
| sb = new StringBuilder(); | |
| } | |
| sb.append(str); | |
| sb.append("\n\n"); | |
| } | |
| /** | |
| * A way to log all around application with time of the log appended | |
| * @param str The text to log with time | |
| */ | |
| public static void log(String str, boolean appendTime) { | |
| if (sb == null) { | |
| sb = new StringBuilder(); | |
| } | |
| sb.append(new SimpleDateFormat("hh:mm:ss", Locale.US).format(new Date())) | |
| .append(" : ") | |
| .append(str); | |
| sb.append("\n\n"); | |
| } | |
| /** | |
| * Gets universial log of the application | |
| * @return String containing all logs | |
| */ | |
| public static String get() { | |
| if (sb == null) { | |
| sb = new StringBuilder(); | |
| } | |
| return sb.toString(); | |
| } | |
| public static void clear() { | |
| sb = null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment