1+ package net .cvs0 .utils ;
2+
3+ import java .time .LocalDateTime ;
4+ import java .time .format .DateTimeFormatter ;
5+
6+ public class Logger
7+ {
8+ private static final String RESET = "\u001B [0m" ;
9+ private static final String RED = "\u001B [31m" ;
10+ private static final String GREEN = "\u001B [32m" ;
11+ private static final String YELLOW = "\u001B [33m" ;
12+ private static final String BLUE = "\u001B [34m" ;
13+ private static final String CYAN = "\u001B [36m" ;
14+ private static final String GRAY = "\u001B [90m" ;
15+ private static final String BOLD = "\u001B [1m" ;
16+
17+ private static final String SUCCESS_EMOJI = "✅" ;
18+ private static final String ERROR_EMOJI = "❌" ;
19+ private static final String WARNING_EMOJI = "⚠️" ;
20+ private static final String INFO_EMOJI = "ℹ️" ;
21+ private static final String DEBUG_EMOJI = "🔍" ;
22+ private static final String PROCESS_EMOJI = "⚙️" ;
23+ private static final String ARROW_EMOJI = "➡️" ;
24+ private static final String CHECKMARK_EMOJI = "✓" ;
25+ private static final String CROSS_EMOJI = "✗" ;
26+
27+ private static boolean verboseMode = false ;
28+ private static boolean colorEnabled = true ;
29+ private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter .ofPattern ("HH:mm:ss" );
30+
31+ public static void setVerbose (boolean verbose )
32+ {
33+ verboseMode = verbose ;
34+ }
35+
36+ public static void setColorEnabled (boolean enabled )
37+ {
38+ colorEnabled = enabled ;
39+ }
40+
41+ public static void success (String message )
42+ {
43+ log (LogLevel .SUCCESS , SUCCESS_EMOJI , GREEN , message );
44+ }
45+
46+ public static void error (String message )
47+ {
48+ log (LogLevel .ERROR , ERROR_EMOJI , RED , message );
49+ }
50+
51+ public static void warning (String message )
52+ {
53+ log (LogLevel .WARNING , WARNING_EMOJI , YELLOW , message );
54+ }
55+
56+ public static void info (String message )
57+ {
58+ log (LogLevel .INFO , INFO_EMOJI , BLUE , message );
59+ }
60+
61+ public static void debug (String message )
62+ {
63+ if (verboseMode ) {
64+ log (LogLevel .DEBUG , DEBUG_EMOJI , GRAY , message );
65+ }
66+ }
67+
68+ public static void process (String message )
69+ {
70+ log (LogLevel .PROCESS , PROCESS_EMOJI , CYAN , message );
71+ }
72+
73+ public static void step (String message )
74+ {
75+ log (LogLevel .STEP , ARROW_EMOJI , BLUE , message );
76+ }
77+
78+ public static void result (String message , boolean isSuccess )
79+ {
80+ if (isSuccess ) {
81+ log (LogLevel .SUCCESS , CHECKMARK_EMOJI , GREEN , message );
82+ } else {
83+ log (LogLevel .ERROR , CROSS_EMOJI , RED , message );
84+ }
85+ }
86+
87+ public static void phase (String phaseName )
88+ {
89+ String separator = "═" .repeat (50 );
90+ log (LogLevel .PHASE , "" , BOLD + CYAN , separator );
91+ log (LogLevel .PHASE , PROCESS_EMOJI , BOLD + CYAN , " " + phaseName .toUpperCase ());
92+ log (LogLevel .PHASE , "" , BOLD + CYAN , separator );
93+ }
94+
95+ public static void subPhase (String subPhaseName )
96+ {
97+ String separator = "─" .repeat (30 );
98+ log (LogLevel .SUB_PHASE , "" , CYAN , separator );
99+ log (LogLevel .SUB_PHASE , ARROW_EMOJI , CYAN , " " + subPhaseName );
100+ log (LogLevel .SUB_PHASE , "" , CYAN , separator );
101+ }
102+
103+ public static void stats (String label , Object value )
104+ {
105+ if (verboseMode ) {
106+ log (LogLevel .STATS , "📊" , GRAY , String .format ("%-20s: %s" , label , value ));
107+ }
108+ }
109+
110+ public static void transformation (String message )
111+ {
112+ if (verboseMode ) {
113+ log (LogLevel .TRANSFORMATION , "🔄" , GRAY , message );
114+ }
115+ }
116+
117+ public static void mapping (String original , String obfuscated )
118+ {
119+ if (verboseMode ) {
120+ log (LogLevel .MAPPING , "🗺️" , GRAY , String .format ("%s → %s" , original , obfuscated ));
121+ }
122+ }
123+
124+ private static void log (LogLevel level , String emoji , String color , String message )
125+ {
126+ String timestamp = LocalDateTime .now ().format (TIME_FORMATTER );
127+ String formattedMessage ;
128+
129+ if (colorEnabled ) {
130+ formattedMessage = String .format ("%s[%s] %s %s%s%s" ,
131+ GRAY , timestamp , emoji , color , message , RESET );
132+ } else {
133+ formattedMessage = String .format ("[%s] %s %s" ,
134+ timestamp , emoji , message );
135+ }
136+
137+ if (level == LogLevel .ERROR ) {
138+ System .err .println (formattedMessage );
139+ } else {
140+ System .out .println (formattedMessage );
141+ }
142+ }
143+
144+ private enum LogLevel
145+ {
146+ SUCCESS , ERROR , WARNING , INFO , DEBUG , PROCESS , STEP , PHASE , SUB_PHASE , STATS , TRANSFORMATION , MAPPING
147+ }
148+ }
0 commit comments