55 * It provides methods to log messages with different severity levels:
66 * INFO, WARN, ERROR, and CRITICAL.
77 *
8+ * Use setShowLogs(true/false) to control console output.
9+ * Logs are always saved to file regardless of the setting.
10+ *
811 * @author Sandro642
912 * @version 1.0
1013 */
1114
1215public class Logger {
1316
14- private Logs logs = new Logs ();
17+ private Logs logs = new Logs ();
18+ private static boolean showLogs = false ; // Default: logs are hidden
19+
20+ /**
21+ * Enable console output for logs.
22+ * Call this method once to display all logs in console.
23+ * By default, logs are only saved to file without console output.
24+ * Logs are always saved to file regardless of this setting.
25+ */
26+ public void showLogs () {
27+ showLogs = true ;
28+ }
1529
16- /**
17- * Method to display an informational message in the console.
18- * This method prints the message in green color and logs it.
19- * @param msg
20- */
21- public void INFO (String msg ) {
22- // Green
23- String INFO = "\u001B [32m[INFO] \u001B [0m" ;
24- System .out .println (INFO + msg );
30+ /**
31+ * Method to display an informational message in the console.
32+ * This method prints the message in green color if showLogs is enabled,
33+ * and always logs it to file.
34+ * @param msg The message to log
35+ */
36+ public void INFO (String msg ) {
37+ if (showLogs ) {
38+ // Green
39+ String INFO = "\u001B [32m[INFO] \u001B [0m" ;
40+ System .out .println (INFO + msg );
41+ }
2542
26- logs .MakeALog (msg , "INFO" );
27- }
43+ logs .MakeALog (msg , "INFO" );
44+ }
2845
29- /**
30- * Method to display a warning message in the console.
31- * This method prints the message in yellow color and logs it.
32- * @param msg
33- */
34- public void WARN (String msg ) {
35- // Yellow
36- String WARN = "\u001B [33m[WARN] \u001B [0m" ;
37- System .out .println (WARN + msg );
46+ /**
47+ * Method to display a warning message in the console.
48+ * This method prints the message in yellow color if showLogs is enabled,
49+ * and always logs it to file.
50+ * @param msg The message to log
51+ */
52+ public void WARN (String msg ) {
53+ if (showLogs ) {
54+ // Yellow
55+ String WARN = "\u001B [33m[WARN] \u001B [0m" ;
56+ System .out .println (WARN + msg );
57+ }
3858
39- logs .MakeALog (msg , "WARN" );
40- }
59+ logs .MakeALog (msg , "WARN" );
60+ }
4161
42- /**
43- * Method to display an error message in the console.
44- * This method prints the message in red color and logs it.
45- * @param msg
46- */
47- public void ERROR (String msg ) {
48- // Red
49- String ERROR = "\u001B [31m[ERROR] \u001B [0m" ;
50- System .out .println (ERROR + msg );
62+ /**
63+ * Method to display an error message in the console.
64+ * This method prints the message in red color if showLogs is enabled,
65+ * and always logs it to file.
66+ * @param msg The message to log
67+ */
68+ public void ERROR (String msg ) {
69+ if (showLogs ) {
70+ // Red
71+ String ERROR = "\u001B [31m[ERROR] \u001B [0m" ;
72+ System .out .println (ERROR + msg );
73+ }
5174
52- logs .MakeALog (msg , "ERROR" );
53- }
75+ logs .MakeALog (msg , "ERROR" );
76+ }
5477
55- /**
56- * Method to display a critical message in the console.
57- * This method prints the message in magenta color and logs it.
58- * @param msg
59- */
60- public void CRITICAL (String msg ) {
61- // Magenta
62- String CRITICAL = "\u001B [35m[CRITICAL] \u001B [0m" ;
63- System .out .println (CRITICAL + msg );
78+ /**
79+ * Method to display a critical message in the console.
80+ * This method prints the message in magenta color if showLogs is enabled,
81+ * and always logs it to file.
82+ * @param msg The message to log
83+ */
84+ public void CRITICAL (String msg ) {
85+ if (showLogs ) {
86+ // Magenta
87+ String CRITICAL = "\u001B [35m[CRITICAL] \u001B [0m" ;
88+ System .out .println (CRITICAL + msg );
89+ }
6490
65- logs .MakeALog (msg , "CRITICAL" );
66- }
67- }
91+ logs .MakeALog (msg , "CRITICAL" );
92+ }
93+ }
0 commit comments