Commit 7706bfa491d85ea04c84e0006040a8c03b83a377
1 parent
4494f1ae
Exists in
master
Use log4j as logging utility.
Showing
12 changed files
with
103 additions
and
52 deletions
Show diff stats
@@ -0,0 +1,5 @@ | @@ -0,0 +1,5 @@ | ||
1 | +log4j.rootLogger=INFO, stdout | ||
2 | +log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
3 | +log4j.appender.stdout.Target=System.out | ||
4 | +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
5 | +log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n |
src/main/java/eu/omp/irap/vespa/epntapclient/EpnTapMainApp.java
@@ -19,8 +19,9 @@ package eu.omp.irap.vespa.epntapclient; | @@ -19,8 +19,9 @@ package eu.omp.irap.vespa.epntapclient; | ||
19 | import javax.swing.JFrame; | 19 | import javax.swing.JFrame; |
20 | import javax.swing.SwingUtilities; | 20 | import javax.swing.SwingUtilities; |
21 | 21 | ||
22 | +import org.apache.log4j.Logger; | ||
23 | + | ||
22 | import eu.omp.irap.vespa.epntapclient.controller.EpnTapController; | 24 | import eu.omp.irap.vespa.epntapclient.controller.EpnTapController; |
23 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
24 | 25 | ||
25 | /** | 26 | /** |
26 | * Simple class to have a main function to launch the EPNTap client. | 27 | * Simple class to have a main function to launch the EPNTap client. |
@@ -29,6 +30,9 @@ import eu.omp.irap.vespa.epntapclient.utils.Log; | @@ -29,6 +30,9 @@ import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
29 | */ | 30 | */ |
30 | public class EpnTapMainApp { | 31 | public class EpnTapMainApp { |
31 | 32 | ||
33 | + /** The logger for this class. */ | ||
34 | + private static final Logger logger = Logger.getLogger(EpnTapMainApp.class); | ||
35 | + | ||
32 | /** Constructor to hide the implicit public one. */ | 36 | /** Constructor to hide the implicit public one. */ |
33 | private EpnTapMainApp() { | 37 | private EpnTapMainApp() { |
34 | } | 38 | } |
@@ -40,7 +44,7 @@ public class EpnTapMainApp { | @@ -40,7 +44,7 @@ public class EpnTapMainApp { | ||
40 | */ | 44 | */ |
41 | public static void main(String[] args) { | 45 | public static void main(String[] args) { |
42 | EpnTapController epnTapControl = new EpnTapController(); | 46 | EpnTapController epnTapControl = new EpnTapController(); |
43 | - Log.LOGGER.info("Lauching EPN-TAP application..."); | 47 | + logger.info("Lauching EPN-TAP application..."); |
44 | if (args.length != 0) { | 48 | if (args.length != 0) { |
45 | System.console().writer().println("Usage: EpnTapMainApp"); | 49 | System.console().writer().println("Usage: EpnTapMainApp"); |
46 | return; | 50 | return; |
src/main/java/eu/omp/irap/vespa/epntapclient/controller/EpnTapController.java
@@ -16,8 +16,9 @@ | @@ -16,8 +16,9 @@ | ||
16 | 16 | ||
17 | package eu.omp.irap.vespa.epntapclient.controller; | 17 | package eu.omp.irap.vespa.epntapclient.controller; |
18 | 18 | ||
19 | +import org.apache.log4j.Logger; | ||
20 | + | ||
19 | import eu.omp.irap.vespa.epntapclient.utils.Const; | 21 | import eu.omp.irap.vespa.epntapclient.utils.Const; |
20 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
21 | import eu.omp.irap.vespa.epntapclient.utils.Queries; | 22 | import eu.omp.irap.vespa.epntapclient.utils.Queries; |
22 | import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView; | 23 | import eu.omp.irap.vespa.epntapclient.view.EpnTapMainView; |
23 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; | 24 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; |
@@ -28,6 +29,9 @@ import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; | @@ -28,6 +29,9 @@ import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; | ||
28 | * @author N. Jourdane | 29 | * @author N. Jourdane |
29 | */ | 30 | */ |
30 | public class EpnTapController { | 31 | public class EpnTapController { |
32 | + /** The logger for this class. */ | ||
33 | + private static final Logger logger = Logger.getLogger(EpnTapController.class); | ||
34 | + | ||
31 | /** The view of EPN-TAP application. */ | 35 | /** The view of EPN-TAP application. */ |
32 | EpnTapMainView view; | 36 | EpnTapMainView view; |
33 | 37 | ||
@@ -85,7 +89,7 @@ public class EpnTapController { | @@ -85,7 +89,7 @@ public class EpnTapController { | ||
85 | String serviceURL = (String) view.getServices().getValueAt(1, row); | 89 | String serviceURL = (String) view.getServices().getValueAt(1, row); |
86 | if (!serviceURL.equals(selectedServiceURL)) { | 90 | if (!serviceURL.equals(selectedServiceURL)) { |
87 | selectedServiceURL = serviceURL; | 91 | selectedServiceURL = serviceURL; |
88 | - Log.LOGGER.info("Selected service URL: " + selectedServiceURL); | 92 | + logger.info("Selected service URL: " + selectedServiceURL); |
89 | } | 93 | } |
90 | } | 94 | } |
91 | 95 | ||
@@ -94,7 +98,7 @@ public class EpnTapController { | @@ -94,7 +98,7 @@ public class EpnTapController { | ||
94 | * @throws VOTableException Can not fill the Table | 98 | * @throws VOTableException Can not fill the Table |
95 | */ | 99 | */ |
96 | public void sendQuery(String query) throws VOTableException { | 100 | public void sendQuery(String query) throws VOTableException { |
97 | - Log.LOGGER.info("Sending query: " + query + " on " + selectedServiceURL); | 101 | + logger.info("Sending query: " + query + " on " + selectedServiceURL); |
98 | resultsController.fillTable(selectedServiceURL, "ADQL", query); | 102 | resultsController.fillTable(selectedServiceURL, "ADQL", query); |
99 | } | 103 | } |
100 | } | 104 | } |
src/main/java/eu/omp/irap/vespa/epntapclient/utils/Log.java
@@ -23,22 +23,25 @@ import java.io.PrintWriter; | @@ -23,22 +23,25 @@ import java.io.PrintWriter; | ||
23 | import java.nio.file.Files; | 23 | import java.nio.file.Files; |
24 | import java.nio.file.Paths; | 24 | import java.nio.file.Paths; |
25 | import java.nio.file.StandardOpenOption; | 25 | import java.nio.file.StandardOpenOption; |
26 | -import java.util.logging.Logger; | 26 | + |
27 | +import org.apache.log4j.Logger; | ||
27 | 28 | ||
28 | import com.google.gson.Gson; | 29 | import com.google.gson.Gson; |
29 | import com.google.gson.GsonBuilder; | 30 | import com.google.gson.GsonBuilder; |
30 | 31 | ||
32 | +import eu.omp.irap.vespa.epntapclient.EpnTapMainApp; | ||
33 | + | ||
31 | /** | 34 | /** |
32 | - * Simple class to provide the logger. | 35 | + * Simple class to provide logging features |
33 | * | 36 | * |
34 | * @author N. Jourdane | 37 | * @author N. Jourdane |
35 | */ | 38 | */ |
36 | public class Log { | 39 | public class Log { |
37 | - /** The logger. */ | ||
38 | - public static final Logger LOGGER = Logger.getAnonymousLogger(); | 40 | + /** The logger for this class. */ |
41 | + private static final Logger logger = Logger.getLogger(EpnTapMainApp.class); | ||
39 | 42 | ||
40 | - /** The log message displayed when errors appends. */ | ||
41 | - public static final String ERROR_MSG = "-- error --\n%1s\nbecause:\n%2s\n-- end of error --\n"; | 43 | + /** The log file path used by `logInFile` and `clearLogFile`. */ |
44 | + private static String logPath = Const.TMP_DIR + "/log"; | ||
42 | 45 | ||
43 | /** Constructor to hide the implicit public one. */ | 46 | /** Constructor to hide the implicit public one. */ |
44 | private Log() { | 47 | private Log() { |
@@ -70,36 +73,39 @@ public class Log { | @@ -70,36 +73,39 @@ public class Log { | ||
70 | writer.write(json); | 73 | writer.write(json); |
71 | 74 | ||
72 | } catch (IOException e) { | 75 | } catch (IOException e) { |
73 | - Log.LOGGER.severe("Can not print in the file: \n" + e); | 76 | + logger.error("Can not print in the file " + path, e); |
74 | } | 77 | } |
75 | 78 | ||
76 | return path; | 79 | return path; |
77 | } | 80 | } |
78 | 81 | ||
79 | - // TODO: Use Log4j instead | 82 | + // TODO: Use log4j FileAppender instead |
80 | 83 | ||
81 | /** | 84 | /** |
82 | * Delete the content of the log file. | 85 | * Delete the content of the log file. |
83 | */ | 86 | */ |
84 | - public static void clearFile() { | ||
85 | - try (PrintWriter writer = new PrintWriter(Const.TMP_DIR + "/log")) { | 87 | + public static void clearLogFile() { |
88 | + try (PrintWriter writer = new PrintWriter(logPath)) { | ||
86 | writer.print(""); | 89 | writer.print(""); |
87 | } catch (FileNotFoundException e) { | 90 | } catch (FileNotFoundException e) { |
88 | - Log.LOGGER.severe("File not found, can not clear it: \n" + e); | 91 | + logger.error("File " + logPath + " not found, can not clear it.", e); |
89 | } | 92 | } |
90 | } | 93 | } |
91 | 94 | ||
95 | + // TODO: Use log4j FileAppender instead | ||
96 | + | ||
92 | /** | 97 | /** |
93 | * Print a message in a log file (named "log"). | 98 | * Print a message in a log file (named "log"). |
94 | * | 99 | * |
95 | * @param text The text to log in the file | 100 | * @param text The text to log in the file |
96 | */ | 101 | */ |
97 | public static void logInFile(Object text) { | 102 | public static void logInFile(Object text) { |
103 | + | ||
98 | try { | 104 | try { |
99 | - Files.write(Paths.get(Const.TMP_DIR + "/log"), (text.toString() + "\n").getBytes(), | 105 | + Files.write(Paths.get(logPath), (text.toString() + "\n").getBytes(), |
100 | StandardOpenOption.APPEND); | 106 | StandardOpenOption.APPEND); |
101 | } catch (IOException e) { | 107 | } catch (IOException e) { |
102 | - Log.LOGGER.severe("Can not print in the file: \n" + e); | 108 | + logger.error("Can not print in the file " + logPath, e); |
103 | } | 109 | } |
104 | } | 110 | } |
105 | 111 |
src/main/java/eu/omp/irap/vespa/epntapclient/view/RequestView.java
@@ -25,7 +25,8 @@ import javax.swing.JLabel; | @@ -25,7 +25,8 @@ import javax.swing.JLabel; | ||
25 | import javax.swing.JPanel; | 25 | import javax.swing.JPanel; |
26 | import javax.swing.JTextArea; | 26 | import javax.swing.JTextArea; |
27 | 27 | ||
28 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | 28 | +import org.apache.log4j.Logger; |
29 | + | ||
29 | import eu.omp.irap.vespa.epntapclient.utils.Queries; | 30 | import eu.omp.irap.vespa.epntapclient.utils.Queries; |
30 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; | 31 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; |
31 | 32 | ||
@@ -34,6 +35,9 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; | @@ -34,6 +35,9 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException; | ||
34 | */ | 35 | */ |
35 | public class RequestView extends JPanel implements ActionListener { | 36 | public class RequestView extends JPanel implements ActionListener { |
36 | 37 | ||
38 | + /** The logger for this class. */ | ||
39 | + private static final Logger logger = Logger.getLogger(RequestView.class); | ||
40 | + | ||
37 | /** The serial version UID (affected with a random number). */ | 41 | /** The serial version UID (affected with a random number). */ |
38 | private static final long serialVersionUID = 1262856496809315405L; | 42 | private static final long serialVersionUID = 1262856496809315405L; |
39 | 43 | ||
@@ -69,7 +73,7 @@ public class RequestView extends JPanel implements ActionListener { | @@ -69,7 +73,7 @@ public class RequestView extends JPanel implements ActionListener { | ||
69 | try { | 73 | try { |
70 | mainView.getController().sendQuery(queryArea.getText()); | 74 | mainView.getController().sendQuery(queryArea.getText()); |
71 | } catch (VOTableException e) { | 75 | } catch (VOTableException e) { |
72 | - Log.LOGGER.warning("Can not send query when clicking on the send button:\n" + e); | 76 | + logger.error("Can not send query when clicking on the send button.", e); |
73 | } | 77 | } |
74 | } | 78 | } |
75 | } | 79 | } |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/VOTableApp.java
@@ -19,9 +19,10 @@ package eu.omp.irap.vespa.epntapclient.votable; | @@ -19,9 +19,10 @@ package eu.omp.irap.vespa.epntapclient.votable; | ||
19 | import javax.swing.JFrame; | 19 | import javax.swing.JFrame; |
20 | import javax.swing.SwingUtilities; | 20 | import javax.swing.SwingUtilities; |
21 | 21 | ||
22 | +import org.apache.log4j.Logger; | ||
23 | + | ||
22 | import com.google.gson.Gson; | 24 | import com.google.gson.Gson; |
23 | 25 | ||
24 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
25 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; | 26 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; |
26 | 27 | ||
27 | /** | 28 | /** |
@@ -31,6 +32,9 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; | @@ -31,6 +32,9 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableController; | ||
31 | */ | 32 | */ |
32 | public class VOTableApp { | 33 | public class VOTableApp { |
33 | 34 | ||
35 | + /** The logger for this class. */ | ||
36 | + static final Logger logger = Logger.getLogger(VOTableApp.class); | ||
37 | + | ||
34 | /** Constructor to hide the implicit public one. */ | 38 | /** Constructor to hide the implicit public one. */ |
35 | private VOTableApp() { | 39 | private VOTableApp() { |
36 | } | 40 | } |
@@ -55,7 +59,7 @@ public class VOTableApp { | @@ -55,7 +59,7 @@ public class VOTableApp { | ||
55 | public static void main(String[] args) { | 59 | public static void main(String[] args) { |
56 | // TODO: Add option to export to CSV and HTML in CLI. | 60 | // TODO: Add option to export to CSV and HTML in CLI. |
57 | VOTableController voTableControl; | 61 | VOTableController voTableControl; |
58 | - Log.LOGGER.info("Lauching VOTable app with arguments:\n " + new Gson().toJson(args)); | 62 | + logger.info("Lauching VOTable app with arguments:\n " + new Gson().toJson(args)); |
59 | if (args.length == 1) { | 63 | if (args.length == 1) { |
60 | voTableControl = new VOTableController(args[0]); | 64 | voTableControl = new VOTableController(args[0]); |
61 | } else if (args.length == 3) { | 65 | } else if (args.length == 3) { |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableConnection.java
@@ -29,8 +29,9 @@ import java.net.URLEncoder; | @@ -29,8 +29,9 @@ import java.net.URLEncoder; | ||
29 | import java.text.SimpleDateFormat; | 29 | import java.text.SimpleDateFormat; |
30 | import java.util.Date; | 30 | import java.util.Date; |
31 | 31 | ||
32 | +import org.apache.log4j.Logger; | ||
33 | + | ||
32 | import eu.omp.irap.vespa.epntapclient.utils.Const; | 34 | import eu.omp.irap.vespa.epntapclient.utils.Const; |
33 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
34 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.BadRequestException; | 35 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.BadRequestException; |
35 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.HTTPRequestException; | 36 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.HTTPRequestException; |
36 | 37 | ||
@@ -40,6 +41,10 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.HTTPRe | @@ -40,6 +41,10 @@ import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.HTTPRe | ||
40 | * @author N. Jourdane | 41 | * @author N. Jourdane |
41 | */ | 42 | */ |
42 | public final class VOTableConnection { | 43 | public final class VOTableConnection { |
44 | + | ||
45 | + /** The logger for this class. */ | ||
46 | + private static final Logger logger = Logger.getLogger(VOTableConnection.class); | ||
47 | + | ||
43 | /** The user agent used for the requests. */ | 48 | /** The user agent used for the requests. */ |
44 | private static final String USER_AGENT = "Mozilla/5.0"; | 49 | private static final String USER_AGENT = "Mozilla/5.0"; |
45 | 50 | ||
@@ -71,7 +76,7 @@ public final class VOTableConnection { | @@ -71,7 +76,7 @@ public final class VOTableConnection { | ||
71 | throw new HTTPRequestException("Can not encode URI " + uri, e); | 76 | throw new HTTPRequestException("Can not encode URI " + uri, e); |
72 | } | 77 | } |
73 | 78 | ||
74 | - Log.LOGGER.info("request: " + uri + "?" + parameters); | 79 | + logger.info("request: " + uri + "?" + parameters); |
75 | VOTableConnection.sendGet(uri, parameters, voTablePath); | 80 | VOTableConnection.sendGet(uri, parameters, voTablePath); |
76 | 81 | ||
77 | return voTablePath; | 82 | return voTablePath; |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableController.java
@@ -18,7 +18,8 @@ package eu.omp.irap.vespa.epntapclient.votable.controller; | @@ -18,7 +18,8 @@ package eu.omp.irap.vespa.epntapclient.votable.controller; | ||
18 | 18 | ||
19 | import java.io.IOException; | 19 | import java.io.IOException; |
20 | 20 | ||
21 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | 21 | +import org.apache.log4j.Logger; |
22 | + | ||
22 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableParsingException; | 23 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableParsingException; |
23 | import eu.omp.irap.vespa.epntapclient.votable.model.Table; | 24 | import eu.omp.irap.vespa.epntapclient.votable.model.Table; |
24 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; | 25 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; |
@@ -29,6 +30,9 @@ import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; | @@ -29,6 +30,9 @@ import eu.omp.irap.vespa.epntapclient.votable.view.VOTableView; | ||
29 | */ | 30 | */ |
30 | public class VOTableController { | 31 | public class VOTableController { |
31 | 32 | ||
33 | + /** The logger for this class. */ | ||
34 | + private static final Logger logger = Logger.getLogger(VOTableController.class); | ||
35 | + | ||
32 | /** The view of the VOTable */ | 36 | /** The view of the VOTable */ |
33 | VOTableView view; | 37 | VOTableView view; |
34 | 38 | ||
@@ -69,7 +73,7 @@ public class VOTableController { | @@ -69,7 +73,7 @@ public class VOTableController { | ||
69 | try { | 73 | try { |
70 | fillTable(VOTableConnection.sendQuery(targetURL, queryLanguage, query)); | 74 | fillTable(VOTableConnection.sendQuery(targetURL, queryLanguage, query)); |
71 | } catch (VOTableException e) { | 75 | } catch (VOTableException e) { |
72 | - Log.LOGGER.info("VOTableController error: " + e); | 76 | + logger.info("VOTableController error: " + e); |
73 | } | 77 | } |
74 | } | 78 | } |
75 | 79 |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableDataParser.java
@@ -23,6 +23,8 @@ import java.util.HashMap; | @@ -23,6 +23,8 @@ import java.util.HashMap; | ||
23 | import java.util.List; | 23 | import java.util.List; |
24 | import java.util.Map; | 24 | import java.util.Map; |
25 | 25 | ||
26 | +import org.apache.log4j.Logger; | ||
27 | + | ||
26 | import com.google.gson.Gson; | 28 | import com.google.gson.Gson; |
27 | 29 | ||
28 | import eu.omp.irap.vespa.epntapclient.utils.Log; | 30 | import eu.omp.irap.vespa.epntapclient.utils.Log; |
@@ -37,6 +39,9 @@ import eu.omp.irap.vespa.epntapclient.votable.model.TableData; | @@ -37,6 +39,9 @@ import eu.omp.irap.vespa.epntapclient.votable.model.TableData; | ||
37 | */ | 39 | */ |
38 | public class VOTableDataParser { | 40 | public class VOTableDataParser { |
39 | 41 | ||
42 | + /** The logger for this class. */ | ||
43 | + private static final Logger logger = Logger.getLogger(VOTableDataParser.class); | ||
44 | + | ||
40 | /** | 45 | /** |
41 | * A list of arrays, representing data stored in the VOTable. Each element is a VOTable row, | 46 | * A list of arrays, representing data stored in the VOTable. Each element is a VOTable row, |
42 | * where arrays elements are in the same order as `columnNames`. | 47 | * where arrays elements are in the same order as `columnNames`. |
@@ -73,7 +78,7 @@ public class VOTableDataParser { | @@ -73,7 +78,7 @@ public class VOTableDataParser { | ||
73 | for (int i = 0; i < fields.size(); i++) { | 78 | for (int i = 0; i < fields.size(); i++) { |
74 | columnsName[i] = fields.get(i).getName(); | 79 | columnsName[i] = fields.get(i).getName(); |
75 | } | 80 | } |
76 | - Log.LOGGER.info("Columns name: " + new Gson().toJson(columnsName)); | 81 | + logger.info("Columns name: " + new Gson().toJson(columnsName)); |
77 | 82 | ||
78 | data = new ArrayList<>(); | 83 | data = new ArrayList<>(); |
79 | 84 | ||
@@ -88,7 +93,7 @@ public class VOTableDataParser { | @@ -88,7 +93,7 @@ public class VOTableDataParser { | ||
88 | } | 93 | } |
89 | 94 | ||
90 | String logPath = Log.printObject(data); | 95 | String logPath = Log.printObject(data); |
91 | - Log.LOGGER.info("A json file representing the VOTable data has been created on " + logPath); | 96 | + logger.info("A json file representing the VOTable data has been created on " + logPath); |
92 | } | 97 | } |
93 | 98 | ||
94 | /** | 99 | /** |
@@ -177,14 +182,12 @@ public class VOTableDataParser { | @@ -177,14 +182,12 @@ public class VOTableDataParser { | ||
177 | * @throws UnsupportedOperationException Data as arrays are not supported yet. | 182 | * @throws UnsupportedOperationException Data as arrays are not supported yet. |
178 | */ | 183 | */ |
179 | private void parseBinaryStream(Stream stream, List<Field> fields) { | 184 | private void parseBinaryStream(Stream stream, List<Field> fields) { |
180 | - Log.LOGGER.info("Parsing data in BINARY stream..."); | 185 | + logger.info("Parsing data in BINARY stream..."); |
181 | String strStream = stream.getValue().replaceAll("(\\r|\\n)", ""); | 186 | String strStream = stream.getValue().replaceAll("(\\r|\\n)", ""); |
182 | - Log.clearFile(); | ||
183 | 187 | ||
184 | bytes = Base64.getDecoder().decode(strStream); | 188 | bytes = Base64.getDecoder().decode(strStream); |
185 | Object[] row = new Object[columnsName.length]; | 189 | Object[] row = new Object[columnsName.length]; |
186 | 190 | ||
187 | - Log.clearFile(); | ||
188 | int nValue = 0; | 191 | int nValue = 0; |
189 | while (cursor < bytes.length) { | 192 | while (cursor < bytes.length) { |
190 | int nColumn = nValue % columnsName.length; | 193 | int nColumn = nValue % columnsName.length; |
@@ -258,7 +261,7 @@ public class VOTableDataParser { | @@ -258,7 +261,7 @@ public class VOTableDataParser { | ||
258 | * @param fields The Fields corresponding to the Table. | 261 | * @param fields The Fields corresponding to the Table. |
259 | */ | 262 | */ |
260 | private static void parseBinary2Stream(Stream stream, List<Field> fields) { | 263 | private static void parseBinary2Stream(Stream stream, List<Field> fields) { |
261 | - Log.LOGGER.info("Parsing data in BINARY2 stream..."); | 264 | + logger.info("Parsing data in BINARY2 stream..."); |
262 | // TODO Implement parseBinary2Stream() | 265 | // TODO Implement parseBinary2Stream() |
263 | } | 266 | } |
264 | 267 | ||
@@ -267,7 +270,7 @@ public class VOTableDataParser { | @@ -267,7 +270,7 @@ public class VOTableDataParser { | ||
267 | * @param fields The Fields corresponding to the Table. | 270 | * @param fields The Fields corresponding to the Table. |
268 | */ | 271 | */ |
269 | private static void parseTableDataStream(TableData tabledata, List<Field> fields) { | 272 | private static void parseTableDataStream(TableData tabledata, List<Field> fields) { |
270 | - Log.LOGGER.info("Parsing data in TABLEDATA stream..."); | 273 | + logger.info("Parsing data in TABLEDATA stream..."); |
271 | // TODO Implement parseTableDataStream() | 274 | // TODO Implement parseTableDataStream() |
272 | } | 275 | } |
273 | 276 | ||
@@ -276,7 +279,7 @@ public class VOTableDataParser { | @@ -276,7 +279,7 @@ public class VOTableDataParser { | ||
276 | * @param fields The Fields corresponding to the Table. | 279 | * @param fields The Fields corresponding to the Table. |
277 | */ | 280 | */ |
278 | private static void parseFITSStream(Stream stream, List<Field> fields) { | 281 | private static void parseFITSStream(Stream stream, List<Field> fields) { |
279 | - Log.LOGGER.info("Parsing data in FITS stream..."); | 282 | + logger.info("Parsing data in FITS stream..."); |
280 | // TODO Implement parseFITSStream() | 283 | // TODO Implement parseFITSStream() |
281 | } | 284 | } |
282 | 285 |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableException.java
@@ -16,9 +16,7 @@ | @@ -16,9 +16,7 @@ | ||
16 | 16 | ||
17 | package eu.omp.irap.vespa.epntapclient.votable.controller; | 17 | package eu.omp.irap.vespa.epntapclient.votable.controller; |
18 | 18 | ||
19 | -import java.util.logging.Level; | ||
20 | - | ||
21 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | 19 | +import org.apache.log4j.Logger; |
22 | 20 | ||
23 | /** | 21 | /** |
24 | * VOTable Exception class. | 22 | * VOTable Exception class. |
@@ -27,35 +25,42 @@ import eu.omp.irap.vespa.epntapclient.utils.Log; | @@ -27,35 +25,42 @@ import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
27 | */ | 25 | */ |
28 | @SuppressWarnings({ "javadoc", "serial" }) | 26 | @SuppressWarnings({ "javadoc", "serial" }) |
29 | public class VOTableException extends Exception { | 27 | public class VOTableException extends Exception { |
28 | + | ||
29 | + /** The logger for this class. */ | ||
30 | + static final Logger logger = Logger.getLogger(VOTableException.class); | ||
31 | + | ||
32 | + /** The log message displayed when errors appends. */ | ||
33 | + private static final String ERROR_MSG = "-- error --\n%1s\nbecause:\n%2s\n-- end of error --\n"; | ||
34 | + | ||
30 | public VOTableException() { | 35 | public VOTableException() { |
31 | - Log.LOGGER.log(Level.SEVERE, "A VOTable error occured."); | 36 | + logger.error("A VOTable error occured."); |
32 | } | 37 | } |
33 | 38 | ||
34 | public VOTableException(String message) { | 39 | public VOTableException(String message) { |
35 | - Log.LOGGER.log(Level.SEVERE, message); | 40 | + logger.error(message); |
36 | } | 41 | } |
37 | 42 | ||
38 | public VOTableException(String message, Exception e) { | 43 | public VOTableException(String message, Exception e) { |
39 | - Log.LOGGER.log(Level.SEVERE, String.format(Log.ERROR_MSG, message, e.getMessage())); | 44 | + logger.error(String.format(ERROR_MSG, message, e.getMessage())); |
40 | } | 45 | } |
41 | 46 | ||
42 | public VOTableException(Exception e) { | 47 | public VOTableException(Exception e) { |
43 | - Log.LOGGER.log(Level.SEVERE, e.getMessage()); | 48 | + logger.error(e.getMessage()); |
44 | } | 49 | } |
45 | 50 | ||
46 | public static class HTTPRequestException extends VOTableException { | 51 | public static class HTTPRequestException extends VOTableException { |
47 | public HTTPRequestException(String message) { | 52 | public HTTPRequestException(String message) { |
48 | - Log.LOGGER.log(Level.SEVERE, message); | 53 | + logger.error(message); |
49 | } | 54 | } |
50 | 55 | ||
51 | public HTTPRequestException(String message, Exception e) { | 56 | public HTTPRequestException(String message, Exception e) { |
52 | - Log.LOGGER.log(Level.SEVERE, String.format(Log.ERROR_MSG, message, e.getMessage())); | 57 | + logger.error(String.format(ERROR_MSG, message, e.getMessage())); |
53 | } | 58 | } |
54 | } | 59 | } |
55 | 60 | ||
56 | public static class VOTableParsingException extends VOTableException { | 61 | public static class VOTableParsingException extends VOTableException { |
57 | public VOTableParsingException(String message, Exception e) { | 62 | public VOTableParsingException(String message, Exception e) { |
58 | - Log.LOGGER.log(Level.SEVERE, String.format(Log.ERROR_MSG, message, e.getMessage())); | 63 | + logger.error(String.format(ERROR_MSG, message, e.getMessage())); |
59 | } | 64 | } |
60 | } | 65 | } |
61 | 66 | ||
@@ -65,7 +70,7 @@ public class VOTableException extends Exception { | @@ -65,7 +70,7 @@ public class VOTableException extends Exception { | ||
65 | public BadRequestException(String message, String info) { | 70 | public BadRequestException(String message, String info) { |
66 | super(message); | 71 | super(message); |
67 | this.info = info; | 72 | this.info = info; |
68 | - Log.LOGGER.log(Level.WARNING, message + "\nDetails: " + info); | 73 | + logger.error(message + "\nDetails: " + info); |
69 | } | 74 | } |
70 | 75 | ||
71 | public String getInfo() { | 76 | public String getInfo() { |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/controller/VOTableParser.java
@@ -31,11 +31,11 @@ import javax.xml.transform.TransformerFactory; | @@ -31,11 +31,11 @@ import javax.xml.transform.TransformerFactory; | ||
31 | import javax.xml.transform.dom.DOMSource; | 31 | import javax.xml.transform.dom.DOMSource; |
32 | import javax.xml.transform.stream.StreamResult; | 32 | import javax.xml.transform.stream.StreamResult; |
33 | 33 | ||
34 | +import org.apache.log4j.Logger; | ||
34 | import org.w3c.dom.Document; | 35 | import org.w3c.dom.Document; |
35 | import org.w3c.dom.NamedNodeMap; | 36 | import org.w3c.dom.NamedNodeMap; |
36 | import org.xml.sax.SAXException; | 37 | import org.xml.sax.SAXException; |
37 | 38 | ||
38 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
39 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableParsingException; | 39 | import eu.omp.irap.vespa.epntapclient.votable.controller.VOTableException.VOTableParsingException; |
40 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; | 40 | import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; |
41 | 41 | ||
@@ -44,6 +44,9 @@ import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; | @@ -44,6 +44,9 @@ import eu.omp.irap.vespa.epntapclient.votable.model.VOTABLE; | ||
44 | */ | 44 | */ |
45 | public final class VOTableParser { | 45 | public final class VOTableParser { |
46 | 46 | ||
47 | + /** The logger for this class. */ | ||
48 | + static final Logger logger = Logger.getLogger(VOTableParser.class); | ||
49 | + | ||
47 | /** The path of the VOTable to verify the VOTable XML file. */ | 50 | /** The path of the VOTable to verify the VOTable XML file. */ |
48 | private static final String VOTABLE_SHEMA = "http://www.ivoa.net/xml/VOTable/v"; | 51 | private static final String VOTABLE_SHEMA = "http://www.ivoa.net/xml/VOTable/v"; |
49 | 52 | ||
@@ -105,11 +108,11 @@ public final class VOTableParser { | @@ -105,11 +108,11 @@ public final class VOTableParser { | ||
105 | 108 | ||
106 | String version = votAttrs.getNamedItem("version").getTextContent(); | 109 | String version = votAttrs.getNamedItem("version").getTextContent(); |
107 | if (version != JAXB_VOTABLE_VERSION) { | 110 | if (version != JAXB_VOTABLE_VERSION) { |
108 | - Log.LOGGER.info("VOTable version is " + version + ", changing VOTable svhema to " | 111 | + logger.info("VOTable version is " + version + ", changing VOTable svhema to " |
109 | + JAXB_VOTABLE_VERSION); | 112 | + JAXB_VOTABLE_VERSION); |
110 | votAttrs.getNamedItem("xmlns").setTextContent(VOTABLE_SHEMA + JAXB_VOTABLE_VERSION); | 113 | votAttrs.getNamedItem("xmlns").setTextContent(VOTABLE_SHEMA + JAXB_VOTABLE_VERSION); |
111 | } else { | 114 | } else { |
112 | - Log.LOGGER.info("VOTable version is " + version + ", everything is ok."); | 115 | + logger.info("VOTable version is " + version + ", everything is ok."); |
113 | } | 116 | } |
114 | 117 | ||
115 | // write the content into xml file | 118 | // write the content into xml file |
src/main/java/eu/omp/irap/vespa/epntapclient/votable/view/VOTableView.java
@@ -18,7 +18,6 @@ package eu.omp.irap.vespa.epntapclient.votable.view; | @@ -18,7 +18,6 @@ package eu.omp.irap.vespa.epntapclient.votable.view; | ||
18 | 18 | ||
19 | import java.awt.BorderLayout; | 19 | import java.awt.BorderLayout; |
20 | import java.util.List; | 20 | import java.util.List; |
21 | -import java.util.logging.Level; | ||
22 | 21 | ||
23 | import javax.swing.JOptionPane; | 22 | import javax.swing.JOptionPane; |
24 | import javax.swing.JPanel; | 23 | import javax.swing.JPanel; |
@@ -29,7 +28,7 @@ import javax.swing.event.TableModelEvent; | @@ -29,7 +28,7 @@ import javax.swing.event.TableModelEvent; | ||
29 | import javax.swing.event.TableModelListener; | 28 | import javax.swing.event.TableModelListener; |
30 | import javax.swing.table.DefaultTableModel; | 29 | import javax.swing.table.DefaultTableModel; |
31 | 30 | ||
32 | -import eu.omp.irap.vespa.epntapclient.utils.Log; | 31 | +import org.apache.log4j.Logger; |
33 | 32 | ||
34 | /** | 33 | /** |
35 | * The main class of the View of the application. | 34 | * The main class of the View of the application. |
@@ -37,6 +36,10 @@ import eu.omp.irap.vespa.epntapclient.utils.Log; | @@ -37,6 +36,10 @@ import eu.omp.irap.vespa.epntapclient.utils.Log; | ||
37 | * @author N. Jourdane | 36 | * @author N. Jourdane |
38 | */ | 37 | */ |
39 | public class VOTableView extends JPanel implements TableModelListener { | 38 | public class VOTableView extends JPanel implements TableModelListener { |
39 | + | ||
40 | + /** The logger for this class. */ | ||
41 | + static final Logger logger = Logger.getLogger(VOTableView.class); | ||
42 | + | ||
40 | // TODO: Create classes VOTableGUI and VOTableCLI which implements an interface VOTableView | 43 | // TODO: Create classes VOTableGUI and VOTableCLI which implements an interface VOTableView |
41 | /** The serial version UID (affected with a random number). */ | 44 | /** The serial version UID (affected with a random number). */ |
42 | private static final long serialVersionUID = -6131752938586134234L; | 45 | private static final long serialVersionUID = -6131752938586134234L; |
@@ -106,7 +109,7 @@ public class VOTableView extends JPanel implements TableModelListener { | @@ -106,7 +109,7 @@ public class VOTableView extends JPanel implements TableModelListener { | ||
106 | */ | 109 | */ |
107 | public void displayError(String message) { | 110 | public void displayError(String message) { |
108 | JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); | 111 | JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); |
109 | - Log.LOGGER.log(Level.WARNING, message); | 112 | + logger.warn(message); |
110 | } | 113 | } |
111 | 114 | ||
112 | /** | 115 | /** |
@@ -116,8 +119,9 @@ public class VOTableView extends JPanel implements TableModelListener { | @@ -116,8 +119,9 @@ public class VOTableView extends JPanel implements TableModelListener { | ||
116 | * @param e The exception displayed in the log for debug. | 119 | * @param e The exception displayed in the log for debug. |
117 | */ | 120 | */ |
118 | public void displayError(String message, Exception e) { | 121 | public void displayError(String message, Exception e) { |
122 | + String error_msg = "-- user error --\n%1s\nbecause:\n%2s\n-- end of user error --\n"; | ||
119 | JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); | 123 | JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); |
120 | - Log.LOGGER.log(Level.SEVERE, String.format(Log.ERROR_MSG, message, e.getMessage())); | 124 | + logger.warn(String.format(error_msg, message, e.getMessage())); |
121 | } | 125 | } |
122 | 126 | ||
123 | @Override | 127 | @Override |