Parcourir la source

Refactored Logger into its own package with seperate enum classes.

git-svn-id: http://svn.dmdirc.com/trunk@170 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Gregory Holmes il y a 17 ans
Parent
révision
35085e2987

+ 30
- 0
src/uk/org/ownage/dmdirc/logger/DebugLevel.java Voir le fichier

@@ -0,0 +1,30 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.logger;
24
+
25
+public enum DebugLevel {        
26
+    NORMAL, 
27
+    FINE, 
28
+    FINER, 
29
+    FINEST
30
+}

+ 30
- 0
src/uk/org/ownage/dmdirc/logger/ErrorLevel.java Voir le fichier

@@ -0,0 +1,30 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.logger;
24
+
25
+public enum ErrorLevel {        
26
+    FATAL, 
27
+    ERROR, 
28
+    WARNING, 
29
+    INFO
30
+}

+ 31
- 0
src/uk/org/ownage/dmdirc/logger/LogLevel.java Voir le fichier

@@ -0,0 +1,31 @@
1
+/*
2
+ * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package uk.org.ownage.dmdirc.logger;
24
+
25
+public enum LogLevel {        
26
+    CORE, 
27
+    COMMAND, 
28
+    PARSER, 
29
+    PLUGIN, 
30
+    UI
31
+}

src/uk/org/ownage/dmdirc/Logger.java → src/uk/org/ownage/dmdirc/logger/Logger.java Voir le fichier

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package uk.org.ownage.dmdirc;
23
+package uk.org.ownage.dmdirc.logger;
24 24
 
25 25
 import java.awt.event.WindowAdapter;
26 26
 import java.awt.event.WindowEvent;
@@ -34,6 +34,7 @@ import java.text.SimpleDateFormat;
34 34
 import java.util.Date;
35 35
 import javax.swing.JDialog;
36 36
 import javax.swing.JOptionPane;
37
+import uk.org.ownage.dmdirc.Config;
37 38
 import uk.org.ownage.dmdirc.ui.MainFrame;
38 39
 
39 40
 /**
@@ -42,10 +43,6 @@ import uk.org.ownage.dmdirc.ui.MainFrame;
42 43
  */
43 44
 public class Logger {
44 45
     
45
-    public enum errorLevel {FATAL, ERROR, WARNING, INFO}
46
-    public enum debugLevel {NORMAL, FINE, FINER, FINEST}
47
-    public enum logLevel {CORE, COMMAND, PARSER, PLUGIN, UI}
48
-    
49 46
     private static PrintWriter logWriter = null;
50 47
     
51 48
     private static JDialog dialog;
@@ -58,7 +55,7 @@ public class Logger {
58 55
     private Logger() {
59 56
     }
60 57
     
61
-    public static void error(Logger.errorLevel level, String message) {
58
+    public static void error(ErrorLevel level, String message) {
62 59
         if (logWriter == null ) createWriter();
63 60
         switch (level) {
64 61
             case FATAL:
@@ -93,12 +90,16 @@ public class Logger {
93 90
         }
94 91
     }
95 92
     
96
-    public static void error(Logger.errorLevel level, Exception message) {
93
+    public static void error(ErrorLevel level, Exception exception) {
97 94
         if (logWriter == null ) createWriter();
95
+        StackTraceElement[] stacktrace = exception.getStackTrace();
98 96
         switch (level) {
99 97
             case FATAL:
100
-                logWriter.println(format.format(new Date())+": ERROR: "+": "+level+" :"+message);
101
-                optionPane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE,
98
+                logWriter.println(format.format(new Date())+": ERROR: "+": "+level+" :"+exception.getMessage());
99
+                for (StackTraceElement traceElement: stacktrace) {
100
+                    logWriter.println("\t\t\t\t"+traceElement);
101
+                }
102
+                optionPane = new JOptionPane(exception.getMessage(), JOptionPane.ERROR_MESSAGE,
102 103
                         JOptionPane.DEFAULT_OPTION);
103 104
                 dialog = new JDialog(MainFrame.getMainFrame(), "Fatal Error",
104 105
                         true);
@@ -123,12 +124,15 @@ public class Logger {
123 124
                 dialog.setVisible(true);
124 125
                 break;
125 126
             default:
126
-                logWriter.println(format.format(new Date())+": ERROR: "+": "+level+" :"+message);
127
+                logWriter.println(format.format(new Date())+": ERROR: "+": "+level+" :"+exception.getMessage());
128
+                for (StackTraceElement traceElement: stacktrace) {
129
+                    logWriter.println("\t\t\t\t"+traceElement);
130
+                }
127 131
                 break;
128 132
         }
129 133
     }
130 134
     
131
-    public static void debug(Logger.debugLevel level, String message) {
135
+    public static void debug(DebugLevel level, String message) {
132 136
         if (logWriter == null ) createWriter();
133 137
         switch(level) {
134 138
             default:
@@ -138,7 +142,7 @@ public class Logger {
138 142
         }
139 143
     }
140 144
     
141
-    public static void log(Logger.logLevel level, String message) {
145
+    public static void log(LogLevel level, String message) {
142 146
         if (logWriter == null ) createWriter();
143 147
         switch(level) {
144 148
             default:
@@ -151,7 +155,7 @@ public class Logger {
151 155
         try {
152 156
             logWriter = new PrintWriter(new BufferedWriter(new FileWriter(Config.getConfigDir()+"errors.log")));
153 157
         } catch (IOException ex) {
154
-            Logger.error(Logger.errorLevel.FATAL, "Oh god, i cant open the error log.");
158
+            Logger.error(ErrorLevel.FATAL, "Oh god, i cant open the error log.");
155 159
         }
156 160
         if (Config.hasOption("logging", "dateFormat")) {
157 161
             format = new SimpleDateFormat(Config.getOption("logging", "dateFormat"));

Chargement…
Annuler
Enregistrer