Browse Source

Add Logger class

Yohan Simard 3 years ago
parent
commit
3e08f1a786
1 changed files with 67 additions and 0 deletions
  1. 67
    0
      src/main/java/fr/insa/clavardator/util/Log.java

+ 67
- 0
src/main/java/fr/insa/clavardator/util/Log.java View File

@@ -0,0 +1,67 @@
1
+package fr.insa.clavardator.util;
2
+
3
+import java.text.SimpleDateFormat;
4
+import java.util.Date;
5
+
6
+public class Log {
7
+    /**
8
+     * Verbose level: 0 = nothing,
9
+     *                1: errors,
10
+     *                2: errors & warnings,
11
+     *                3: errors & warnings & debug,
12
+     *                4: all
13
+     */
14
+    public static int verboseLevel = 0;
15
+    
16
+    public static void v(String prefix, String message) {
17
+        v(prefix, message, null);
18
+    }
19
+    public static void v(String prefix, String message, Exception e) {
20
+        if (verboseLevel >= 4) {
21
+            Date date = new Date();
22
+            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
23
+            System.out.println(sdf.format(date) + " | V | "+ prefix + ": " + message);
24
+            if (e != null)
25
+                e.printStackTrace();
26
+        }
27
+    }
28
+
29
+    public static void d(String prefix, String message) {
30
+        d(prefix, message, null);
31
+    }
32
+    public static void d(String prefix, String message, Exception e) {
33
+        if (verboseLevel >= 3) {
34
+            Date date = new Date();
35
+            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
36
+            System.out.println(sdf.format(date) + " | D | "+ prefix + ": " + message);
37
+            if (e != null)
38
+                e.printStackTrace();
39
+        }
40
+    }
41
+
42
+    public static void w(String prefix, String message) {
43
+        w(prefix, message, null);
44
+    }
45
+    public static void w(String prefix, String message, Exception e) {
46
+        if (verboseLevel >= 2) {
47
+            Date date = new Date();
48
+            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
49
+            System.out.println(sdf.format(date) + " | W | "+ prefix + ": " + message);
50
+            if (e != null)
51
+                e.printStackTrace();
52
+        }
53
+    }
54
+
55
+    public static void e(String prefix, String message) {
56
+        e(prefix, message, null);
57
+    }
58
+    public static void e(String prefix, String message, Exception e) {
59
+        if (verboseLevel >= 1) {
60
+            Date date = new Date();
61
+            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
62
+            System.out.println(sdf.format(date) + " | E | "+ prefix + " " + message);
63
+            if (e != null)
64
+                e.printStackTrace();
65
+        }
66
+    }
67
+}

Loading…
Cancel
Save