Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use java.util.logging for logging #270

Merged
merged 29 commits into from

1 participant

@amolenaar
Collaborator

We have no default logging mechanism. Currently part is done by System.out and an access log is made using a custom logger, if configured.

It would be nice to have a default way to do logging. Since we try to depend on as little libraries as possible, it makes sense to use java.util.logging for this purpose.

The work I see is setting up a logging configuration (probably configured from plugins.properties). Also a proper default (console?) logging configuration can be set up.

@amolenaar
Collaborator

In addition we can add a -v option for verbose output. Depending on the log level more (debug) logging can be shown. The configuration can be set on load and can be overridden by a plugin.

amolenaar added some commits
@amolenaar amolenaar Add logging in FitNesseMain. 70629a2
@amolenaar amolenaar Provide simple log formatter. d27aeeb
@amolenaar amolenaar Move Arguments to fitnesseMain 5983a71
@amolenaar amolenaar Copy logging properties as part of compile step. c56c83b
@amolenaar amolenaar Add -v option. Allows for debug logging 16c4f3e
@amolenaar amolenaar Only add log level for > INFO messages. b5853db
@amolenaar amolenaar Update logger format c5259e8
@amolenaar amolenaar Let FitNesse main class use logger instead of System.err a9670cd
@amolenaar amolenaar Let updater use logger instead of System.err 62298e2
@amolenaar amolenaar Use logger for wiki components, instead of System.err and e.printStac…
…kTrace()
e05f1ae
@amolenaar amolenaar Use logger for responders 89b2223
@amolenaar amolenaar Print stack traces for log messages warning and up. 94d0b4a
@amolenaar amolenaar Added comment for logger bafd49f
@amolenaar amolenaar Fix FitNessMain unit test. Stuff is logged on stderr now. d6896ca
@amolenaar amolenaar Use Ant logger for Ant Tasks. aa53040
@amolenaar amolenaar Use Logger where System.{out|err} was used. Except for usage messages. 7250357
@amolenaar amolenaar Remove unneeded catch clauses from fitnesse.wikitext package. 28b9fd9
@amolenaar amolenaar Remove e.printStackTrace from fitnesse package cbcaba3
@amolenaar amolenaar Remove unneeded throws definition from fitnesse.authentication.Secure…
…Operation.
3134cf6
@amolenaar amolenaar Remove e.printStackTrace from fitnesse.reporting 44bd6b4
@amolenaar amolenaar Remove e.printStackTrace from fitnesse.responders 406dd24
@amolenaar amolenaar Remove e.printStackTrace from fitnesse.testrunner 6e02b49
@amolenaar amolenaar Remove e.printStackTrace from fitnesse.testsystems 546ce83
@amolenaar amolenaar Clean up page creator class 2ef9817
@amolenaar amolenaar add -v option to usage message 24ef610
@amolenaar amolenaar Few more places where e.printStackTrace can be replaced by logging. 76e60e4
@amolenaar amolenaar Use class name for logger, instead of subsystem name. Seems like ever…
…ybody does it this way.
d68e271
@amolenaar amolenaar Do not log class name. 84f0897
@amolenaar amolenaar merged commit 84f0897 into unclebob:master
@amolenaar amolenaar deleted the amolenaar:java-logging branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 18, 2013
  1. @amolenaar
Commits on Sep 19, 2013
  1. @amolenaar

    Add logging in FitNesseMain.

    amolenaar authored
  2. @amolenaar
  3. @amolenaar
  4. @amolenaar
  5. @amolenaar
  6. @amolenaar
Commits on Sep 20, 2013
  1. @amolenaar

    Update logger format

    amolenaar authored
  2. @amolenaar
  3. @amolenaar
  4. @amolenaar
  5. @amolenaar

    Use logger for responders

    amolenaar authored
  6. @amolenaar
  7. @amolenaar

    Added comment for logger

    amolenaar authored
  8. @amolenaar
  9. @amolenaar
  10. @amolenaar
Commits on Sep 21, 2013
  1. @amolenaar
  2. @amolenaar
  3. @amolenaar
  4. @amolenaar
  5. @amolenaar
  6. @amolenaar
  7. @amolenaar
  8. @amolenaar

    Clean up page creator class

    amolenaar authored
  9. @amolenaar
  10. @amolenaar
Commits on Sep 23, 2013
  1. @amolenaar
  2. @amolenaar

    Do not log class name.

    amolenaar authored
This page is out of date. Refresh to see the latest.
Showing with 494 additions and 381 deletions.
  1. +3 −1 build.xml
  2. +7 −8 src/fitnesse/FitNesse.java
  3. +2 −14 src/fitnesse/FitNesseContext.java
  4. +9 −5 src/fitnesse/FitNesseExpediter.java
  5. +5 −1 src/fitnesse/FitNesseServer.java
  6. +6 −2 src/fitnesse/FitNesseVersion.java
  7. +18 −31 src/fitnesse/PluginsLoader.java
  8. +7 −21 src/fitnesse/PluginsLoaderTest.java
  9. +6 −4 src/fitnesse/Shutdown.java
  10. +6 −9 src/fitnesse/authentication/Authenticator.java
  11. +1 −1  src/fitnesse/authentication/InsecureOperation.java
  12. +1 −1  src/fitnesse/authentication/SecureOperation.java
  13. +1 −1  src/fitnesse/authentication/SecurePageOperation.java
  14. +1 −0  src/fitnesse/components/Logger.java
  15. +12 −19 src/fitnesse/fixtures/PageCreator.java
  16. +2 −1  src/fitnesse/http/UploadedFile.java
  17. +5 −2 src/fitnesse/junit/PrintTestListener.java
  18. +1 −1  src/fitnesse/junit/TestHelper.java
  19. +50 −0 src/fitnesse/logging/LogFormatter.java
  20. +61 −0 src/fitnesse/logging/LogFormatterTest.java
  21. +5 −2 src/fitnesse/reporting/BaseFormatter.java
  22. +3 −2 src/fitnesse/reporting/XmlFormatter.java
  23. +4 −2 src/fitnesse/reporting/history/MostRecentPageHistoryReader.java
  24. +5 −2 src/fitnesse/responders/ChunkingResponder.java
  25. +5 −1 src/fitnesse/responders/ImportAndViewResponder.java
  26. +5 −1 src/fitnesse/responders/ResponderFactory.java
  27. +6 −1 src/fitnesse/responders/ShutdownResponder.java
  28. +6 −4 src/fitnesse/responders/WikiImportTestEventListener.java
  29. +0 −2  src/fitnesse/responders/WikiImportingResponderTest.java
  30. +1 −2  src/fitnesse/responders/run/TestResultFormattingResponder.java
  31. +0 −1  src/fitnesse/responders/versions/VersionComparerTest.java
  32. +6 −1 src/fitnesse/schedule/ScheduleImpl.java
  33. +0 −2  src/fitnesse/slim/test/TestSlim.java
  34. +7 −11 src/fitnesse/socketservice/SocketService.java
  35. +4 −1 src/fitnesse/testrunner/MultipleTestsRunner.java
  36. +4 −1 src/fitnesse/testrunner/RunningTestingTracker.java
  37. +4 −1 src/fitnesse/testrunner/SuiteContentsFinder.java
  38. +5 −1 src/fitnesse/testrunner/SuiteFilter.java
  39. +7 −4 src/fitnesse/testsystems/CommandRunner.java
  40. +5 −2 src/fitnesse/testsystems/fit/FitClient.java
  41. +6 −1 src/fitnesse/testsystems/fit/FitSocketReceiver.java
  42. +5 −1 src/fitnesse/testsystems/fit/SimpleSocketDoner.java
  43. +5 −1 src/fitnesse/testsystems/slim/HtmlTable.java
  44. +5 −2 src/fitnesse/testsystems/slim/SlimClientBuilder.java
  45. +5 −2 src/fitnesse/testsystems/slim/SlimTestSystem.java
  46. +4 −1 src/fitnesse/testsystems/slim/tables/SlimTableFactory.java
  47. +1 −0  src/fitnesse/testutil/ClassTranslatePoint.java
  48. +1 −0  src/fitnesse/testutil/ObjectTranslatePoint.java
  49. +1 −0  src/fitnesse/testutil/PassFixture.java
  50. +1 −0  src/fitnesse/testutil/VectorSum.java
  51. +4 −5 src/fitnesse/updates/UpdateFileList.java
  52. +0 −1  src/fitnesse/updates/UpdateFileListTest.java
  53. +8 −7 src/fitnesse/updates/UpdaterBase.java
  54. +8 −14 src/fitnesse/updates/UpdaterImplementation.java
  55. +0 −1  src/fitnesse/updates/UpdaterImplementationTest.java
  56. +0 −1  src/fitnesse/updates/UpdaterTest.java
  57. +0 −3  src/fitnesse/util/HtmlParserToolsTest.java
  58. +1 −1  src/fitnesse/wiki/ClassPathBuilder.java
  59. +3 −4 src/fitnesse/wiki/PageData.java
  60. +4 −1 src/fitnesse/wiki/WikiPageProperties.java
  61. +4 −2 src/fitnesse/wiki/fs/SimpleFileVersionsController.java
  62. +0 −1  src/fitnesse/wiki/fs/VersionsControllerFixture.java
  63. +7 −4 src/fitnesse/wiki/fs/ZipFileVersionsController.java
  64. +6 −1 src/fitnesse/wiki/refactoring/MovedPageReferenceRenamer.java
  65. +6 −1 src/fitnesse/wiki/refactoring/PageReferenceRenamer.java
  66. +5 −1 src/fitnesse/wiki/search/WhereUsedPageFinder.java
  67. +0 −7 src/fitnesse/wikitext/Utils.java
  68. +2 −7 src/fitnesse/wikitext/parser/ContentsItemBuilder.java
  69. +0 −3  src/fitnesse/wikitext/parser/ParsedPage.java
  70. +36 −103 src/fitnesse/wikitext/parser/WikiSourcePage.java
  71. +13 −3 src/{fitnesse → fitnesseMain}/Arguments.java
  72. +1 −2  src/{fitnesse → fitnesseMain}/ArgumentsTest.java
  73. +53 −26 src/fitnesseMain/FitNesseMain.java
  74. +4 −4 src/fitnesseMain/FitNesseMainTest.java
  75. +1 −1  src/fitnesseMain/ant/ExecuteFitnesseTestsTask.java
  76. +2 −0  src/fitnesseMain/logging.properties
  77. +4 −0 src/fitnesseMain/verbose-logging.properties
  78. +2 −3 src/util/FileUtil.java
View
4 build.xml
@@ -33,6 +33,7 @@
<target name="run" depends="compile, compile-bootstrap-less, retrieve" description="Start FitNesse from the command line">
<java classpathref="classpath" classname="fitnesseMain.FitNesseMain" fork="true" failonerror="true">
<arg value="-o" />
+ <arg value="-v" />
<arg value="-p" />
<arg value="${port}" />
</java>
@@ -51,7 +52,7 @@
<exclude name="**/*TestSuite.class" />
<include name="fitnesse/resources/**" />
<include name="Resources/**" />
- <include name="tasks.properties" />
+ <include name="**/*.properties" />
<include name="META-INF/FitNesseVersion.txt" />
<fileset dir="${classes.dir}" includes="**/SystemUnderTest.class,**/MySystemUnderTest.class" />
@@ -116,6 +117,7 @@
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="fitnesse/resources/**" />
+ <include name="**/*.properties" />
</fileset>
</copy>
</target>
View
15 src/fitnesse/FitNesse.java
@@ -14,8 +14,11 @@
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.BindException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class FitNesse {
+ private static final Logger LOG = Logger.getLogger(FitNesse.class.getName());
public static final FitNesseVersion VERSION = new FitNesseVersion();
public static FitNesse FITNESSE_INSTANCE;
private final Updater updater;
@@ -68,19 +71,15 @@ public boolean start() {
}
return true;
} catch (BindException e) {
- printBadPortMessage(context.port);
+ LOG.severe("FitNesse cannot be started...");
+ LOG.severe("Port " + context.port + " is already in use.");
+ LOG.severe("Use the -p <port#> command line argument to use a different port.");
} catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.SEVERE, "Error while starting the FitNesse socket service", e);
}
return false;
}
- private static void printBadPortMessage(int port) {
- System.err.println("FitNesse cannot be started...");
- System.err.println("Port " + port + " is already in use.");
- System.err.println("Use the -p <port#> command line argument to use a different port.");
- }
-
public void stop() throws IOException {
if (theService != null) {
theService.close();
View
16 src/fitnesse/FitNesseContext.java
@@ -17,6 +17,7 @@
public final static String recentChangesDateFormat = "kk:mm:ss EEE, MMM dd, yyyy";
public final static String rfcCompliantDateFormat = "EEE, d MMM yyyy HH:mm:ss Z";
public static final String testResultsDirectoryName = "testResults";
+ public static final int DEFAULT_PORT = 80;
/**
@@ -95,25 +96,12 @@ private FitNesseContext(WikiPage root, String rootPath,
this.pageTheme = pageTheme != null ? pageTheme : "fitnesse_straight";
this.defaultNewPageContent = defaultNewPageContent != null ? defaultNewPageContent : "!contents -R2 -g -p -f -h";
this.recentChanges = recentChanges;
- this.port = port >= 0 ? port : 80;
+ this.port = port >= 0 ? port : DEFAULT_PORT;
this.authenticator = authenticator != null ? authenticator : new PromiscuousAuthenticator();
this.logger = logger;
responderFactory = new ResponderFactory(getRootPagePath());
}
- public String toString() {
- String endl = System.getProperty("line.separator");
- StringBuffer buffer = new StringBuffer();
- buffer.append("\t").append("port: ").append(port).append(endl);
- buffer.append("\t").append("root page: ").append(root).append(endl);
- buffer.append("\t").append("logger: ").append(logger == null ? "none" : logger.toString()).append(endl);
- buffer.append("\t").append("authenticator: ").append(authenticator).append(endl);
- buffer.append("\t").append("page factory: ").append(pageFactory).append(endl);
- buffer.append("\t").append("page theme: ").append(pageTheme).append(endl);
-
- return buffer.toString();
- }
-
public File getTestHistoryDirectory() {
return new File(String.format("%s/files/%s", getRootPagePath(), testResultsDirectoryName));
}
View
14 src/fitnesse/FitNesseExpediter.java
@@ -18,8 +18,12 @@
import java.net.Socket;
import java.net.SocketException;
import java.util.GregorianCalendar;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class FitNesseExpediter implements ResponseSender {
+ private static final Logger LOG = Logger.getLogger(FitNesseExpediter.class.getName());
+
private Socket socket;
private InputStream input;
private OutputStream output;
@@ -49,7 +53,7 @@ public void start() {
// can be thrown by makeResponse or sendResponse.
}
catch (Throwable e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unexpected exception", e);
}
}
@@ -66,8 +70,8 @@ public void send(byte[] bytes) {
output.write(bytes);
output.flush();
}
- catch (IOException stopButtonPressed_probably) {
- // TODO: Log this
+ catch (IOException e) {
+ LOG.log(Level.INFO, "Output stream closed unexpectedly (Stop button pressed?)", e);
}
}
@@ -77,7 +81,7 @@ public void close() {
socket.close();
}
catch (IOException e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Error while closing socket", e);
}
}
@@ -177,7 +181,7 @@ private void reportError(int status, String message) {
hasError = true;
}
catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Can not report error (status = " + status + ", message = " + message + ")", e);
}
}
View
6 src/fitnesse/FitNesseServer.java
@@ -3,10 +3,14 @@
package fitnesse;
import java.net.Socket;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.socketservice.SocketServer;
public class FitNesseServer implements SocketServer {
+ private static final Logger LOG = Logger.getLogger(FitNesseServer.class.getName());
+
private FitNesseContext context;
public FitNesseServer(FitNesseContext context) {
@@ -24,7 +28,7 @@ public void serve(Socket s, long requestTimeout) {
sender.start();
}
catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.SEVERE, "Error while serving socket " + s, e);
}
}
}
View
8 src/fitnesse/FitNesseVersion.java
@@ -5,12 +5,16 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
* Represents a version of a fitnesse release. Versions have the following format: v20100103[suffix]
* I.e. the suffix is optional.
**/
public class FitNesseVersion {
+ private static final Logger LOG = Logger.getLogger(FitNesseVersion.class.getName());
+
private final String version;
public FitNesseVersion() {
@@ -32,14 +36,14 @@ private static String versionFromMetaInf() {
int len = is.read(b);
return new String(b, 0, len, Charset.forName("ISO-8859-1"));
} catch (IOException e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to read FitNesse version", e);
return "unknown";
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.log(Level.SEVERE, "Unable to close FitNesse version file (should never happen)", e);
}
}
}
View
49 src/fitnesse/PluginsLoader.java
@@ -22,7 +22,7 @@
public class PluginsLoader {
- private final String endl = System.getProperty("line.separator");
+ java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(PluginsLoader.class.getName());
private final ComponentFactory componentFactory;
@@ -30,56 +30,50 @@ public PluginsLoader(ComponentFactory componentFactory) {
this.componentFactory = componentFactory;
}
- public String loadPlugins(ResponderFactory responderFactory, SymbolProvider symbolProvider) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException {
- StringBuffer buffer = new StringBuffer();
+ public void loadPlugins(ResponderFactory responderFactory, SymbolProvider symbolProvider) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException {
String[] responderPlugins = getListFromProperties(PLUGINS);
if (responderPlugins != null) {
- buffer.append("\tCustom plugins loaded:").append(endl);
for (String responderPlugin : responderPlugins) {
Class<?> pluginClass = Class.forName(responderPlugin);
- loadRespondersFromPlugin(pluginClass, responderFactory, buffer);
- loadSymbolTypesFromPlugin(pluginClass, symbolProvider, buffer);
+ loadRespondersFromPlugin(pluginClass, responderFactory);
+ loadSymbolTypesFromPlugin(pluginClass, symbolProvider);
}
}
- return buffer.toString();
}
- private void loadRespondersFromPlugin(Class<?> pluginClass, ResponderFactory responderFactory, StringBuffer buffer)
- throws IllegalAccessException, InvocationTargetException {
+ private void loadRespondersFromPlugin(Class<?> pluginClass, ResponderFactory responderFactory)
+ throws IllegalAccessException, InvocationTargetException {
try {
Method method = pluginClass.getMethod("registerResponders", ResponderFactory.class);
method.invoke(pluginClass, responderFactory);
- buffer.append("\t\t").append("responders:").append(pluginClass.getName()).append(endl);
+ LOG.info("Loaded responder : " + pluginClass.getName());
} catch (NoSuchMethodException e) {
// ok, no responders to register in this plugin
}
}
- private void loadSymbolTypesFromPlugin(Class<?> pluginClass, SymbolProvider symbolProvider, StringBuffer buffer)
- throws IllegalAccessException, InvocationTargetException {
+ private void loadSymbolTypesFromPlugin(Class<?> pluginClass, SymbolProvider symbolProvider)
+ throws IllegalAccessException, InvocationTargetException {
try {
Method method = pluginClass.getMethod("registerSymbolTypes", SymbolProvider.class);
method.invoke(pluginClass, symbolProvider);
- buffer.append("\t\t").append("widgets:").append(pluginClass.getName()).append(endl);
+ LOG.info("Loaded SymbolType: " + pluginClass.getName());
} catch (NoSuchMethodException e) {
// ok, no widgets to register in this plugin
}
}
- public String loadResponders(ResponderFactory responderFactory) throws ClassNotFoundException {
- StringBuffer buffer = new StringBuffer();
+ public void loadResponders(ResponderFactory responderFactory) throws ClassNotFoundException {
String[] responderList = getListFromProperties(RESPONDERS);
if (responderList != null) {
- buffer.append("\tCustom responders loaded:").append(endl);
for (String responder : responderList) {
String[] values = responder.trim().split(":");
String key = values[0];
String className = values[1];
responderFactory.addResponder(key, className);
- buffer.append("\t\t").append(key).append(":").append(className).append(endl);
+ LOG.info("Loaded responder " + key + ":" + className);
}
}
- return buffer.toString();
}
private String[] getListFromProperties(String propertyName) {
@@ -113,35 +107,29 @@ public Authenticator getAuthenticator(Authenticator defaultAuthenticator) {
return authenticator == null ? defaultAuthenticator : authenticator;
}
- public String loadSymbolTypes(SymbolProvider symbolProvider) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
- StringBuffer buffer = new StringBuffer();
+ public void loadSymbolTypes(SymbolProvider symbolProvider) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
String[] symbolTypeNames = getListFromProperties(SYMBOL_TYPES);
if (symbolTypeNames != null) {
- buffer.append("\tCustom symbol types loaded:").append(endl);
for (String symbolTypeName : symbolTypeNames) {
Class<?> symbolTypeClass = Class.forName(symbolTypeName.trim());
symbolProvider.add((SymbolType)symbolTypeClass.newInstance());
- buffer.append("\t\t").append(symbolTypeClass.getName()).append(endl);
+ LOG.info("Loaded SymbolType " + symbolTypeClass.getName());
}
}
- return buffer.toString();
}
- public String loadContentFilter() {
+ public void loadContentFilter() {
ContentFilter filter = (ContentFilter) componentFactory.createComponent(CONTENT_FILTER);
if (filter != null) {
SaveResponder.contentFilter = filter;
- return "\tContent filter installed: " + filter.getClass().getName() + "\n";
+ LOG.info("Content filter installed: " + filter.getClass().getName());
}
- return "";
}
@SuppressWarnings("unchecked")
- public String loadSlimTables() throws ClassNotFoundException {
- StringBuffer buffer = new StringBuffer();
+ public void loadSlimTables() throws ClassNotFoundException {
String[] tableList = getListFromProperties(SLIM_TABLES);
if (tableList != null) {
- buffer.append("\tCustom SLiM table types loaded:").append(endl);
for (String table : tableList) {
table = table.trim();
int colonIndex = table.lastIndexOf(':');
@@ -149,10 +137,9 @@ public String loadSlimTables() throws ClassNotFoundException {
String className = table.substring(colonIndex + 1, table.length());
SlimTableFactory.addTableType(key, (Class<? extends SlimTable>) Class.forName(className));
- buffer.append("\t\t").append(key).append(":").append(className).append(endl);
+ LOG.info("Loaded custom SLiM table type "+ key + ":" + className);
}
}
- return buffer.toString();
}
}
View
28 src/fitnesse/PluginsLoaderTest.java
@@ -66,9 +66,7 @@ public void testAddPlugins() throws Exception {
assertMatch("!today", false);
- String output = loader.loadPlugins(responderFactory, testProvider);
-
- assertSubString(DummyPlugin.class.getName(), output);
+ loader.loadPlugins(responderFactory, testProvider);
assertEquals(WikiPageResponder.class, responderFactory.getResponderClass("custom1"));
assertEquals(EditResponder.class, responderFactory.getResponderClass("custom2"));
@@ -86,10 +84,7 @@ public void testAddResponderPlugins() throws Exception {
testProperties.setProperty(ComponentFactory.RESPONDERS, respondersValue);
ResponderFactory responderFactory = new ResponderFactory(".");
- String output = loader.loadResponders(responderFactory);
-
- assertSubString("custom1:" + WikiPageResponder.class.getName(), output);
- assertSubString("custom2:" + EditResponder.class.getName(), output);
+ loader.loadResponders(responderFactory);
assertEquals(WikiPageResponder.class, responderFactory.getResponderClass("custom1"));
assertEquals(EditResponder.class, responderFactory.getResponderClass("custom2"));
@@ -100,9 +95,7 @@ public void testWikiWidgetPlugins() throws Exception {
String symbolValues = Today.class.getName();
testProperties.setProperty(ComponentFactory.SYMBOL_TYPES, symbolValues);
- String output = loader.loadSymbolTypes(testProvider);
-
- assertSubString(Today.class.getName(), output);
+ loader.loadSymbolTypes(testProvider);
assertMatch("!today", true);
}
@@ -151,13 +144,12 @@ public void testMakeMultiUserAuthenticator() throws Exception {
@Test
public void testContentFilterCreation() throws Exception {
- assertEquals("", loader.loadContentFilter());
+ loader.loadContentFilter();
assertEquals(null, SaveResponder.contentFilter);
testProperties.setProperty(ComponentFactory.CONTENT_FILTER, TestContentFilter.class.getName());
- String content = loader.loadContentFilter();
- assertEquals("\tContent filter installed: " + SaveResponder.contentFilter.getClass().getName() + "\n", content);
+ loader.loadContentFilter();
assertNotNull(SaveResponder.contentFilter);
assertEquals(TestContentFilter.class, SaveResponder.contentFilter.getClass());
}
@@ -165,10 +157,7 @@ public void testContentFilterCreation() throws Exception {
@Test
public void testSlimTablesCreation() throws ClassNotFoundException {
testProperties.setProperty(ComponentFactory.SLIM_TABLES, "test:" + TestSlimTable.class.getName());
- String content = loader.loadSlimTables();
-
- assertTrue(content.contains("test:"));
- assertTrue(content.contains("TestSlimTable"));
+ loader.loadSlimTables();
HtmlTable table = makeMockTable("test");
SlimTable slimTable = new SlimTableFactory().makeSlimTable(table, "foo", new SlimTestContextImpl());
@@ -178,10 +167,7 @@ public void testSlimTablesCreation() throws ClassNotFoundException {
@Test
public void testSlimTablesWithColonCreation() throws ClassNotFoundException {
testProperties.setProperty(ComponentFactory.SLIM_TABLES, "test::" + TestSlimTable.class.getName());
- String content = loader.loadSlimTables();
-
- assertTrue(content.contains("test:"));
- assertTrue(content.contains("TestSlimTable"));
+ loader.loadSlimTables();
HtmlTable table = makeMockTable("test:");
SlimTable slimTable = new SlimTableFactory().makeSlimTable(table, "foo", new SlimTestContextImpl());
View
10 src/fitnesse/Shutdown.java
@@ -5,6 +5,7 @@
package fitnesse;
import java.io.IOException;
+import java.util.logging.Logger;
import fitnesse.http.RequestBuilder;
import fitnesse.http.Response;
@@ -12,8 +13,10 @@
import util.CommandLine;
public class Shutdown {
+ private static final Logger LOG = Logger.getLogger(Shutdown.class.getName());
+
public String hostname = "localhost";
- public int port = Arguments.DEFAULT_PORT;
+ public int port = FitNesseContext.DEFAULT_PORT;
public String username;
public String password;
private CommandLine commandLine = new CommandLine("[-h hostname] [-p port] [-c username password]");
@@ -31,8 +34,7 @@ private void run(String[] args) throws Exception {
String status = checkResponse(response);
if (!"OK".equals(status)) {
- System.err.println("Failed to shutdown.");
- System.err.println(status);
+ LOG.warning("Failed to shutdown. Status = " + status);
System.exit(response.getStatus());
}
}
@@ -79,7 +81,7 @@ public boolean parseArgs(String[] args) {
public void usage() {
System.err.println("Usage: java fitnesse.Shutdown [-hpc]");
System.err.println("\t-h <hostname> {localhost}");
- System.err.println("\t-p <port number> {" + Arguments.DEFAULT_PORT + "}");
+ System.err.println("\t-p <port number> {" + FitNesseContext.DEFAULT_PORT + "}");
System.err.println("\t-c <username> <password> Supply user credentials. Use when FitNesse has authentication activated.");
System.exit(-1);
}
View
15 src/fitnesse/authentication/Authenticator.java
@@ -2,6 +2,9 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.authentication;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import fitnesse.FitNesseContext;
import fitnesse.Responder;
import fitnesse.http.Request;
@@ -25,16 +28,10 @@ else if (!isSecureResponder(privilegedResponder))
private Responder verifyOperationIsSecure(Responder privilegedResponder, FitNesseContext context, Request request) {
SecureOperation so = ((SecureResponder) privilegedResponder).getSecureOperation();
- try {
- if (so.shouldAuthenticate(context, request))
- return unauthorizedResponder(context, request);
- else
- return privilegedResponder;
- }
- catch (Exception e) {
- e.printStackTrace();
+ if (so.shouldAuthenticate(context, request))
return unauthorizedResponder(context, request);
- }
+ else
+ return privilegedResponder;
}
protected Responder unauthorizedResponder(FitNesseContext context, Request request) {
View
2  src/fitnesse/authentication/InsecureOperation.java
@@ -4,7 +4,7 @@
import fitnesse.http.Request;
public class InsecureOperation implements SecureOperation {
- public boolean shouldAuthenticate(FitNesseContext context, Request request) throws Exception {
+ public boolean shouldAuthenticate(FitNesseContext context, Request request) {
return false;
}
}
View
2  src/fitnesse/authentication/SecureOperation.java
@@ -6,5 +6,5 @@
import fitnesse.http.Request;
public interface SecureOperation {
- public abstract boolean shouldAuthenticate(FitNesseContext context, Request request) throws Exception;
+ public abstract boolean shouldAuthenticate(FitNesseContext context, Request request);
}
View
2  src/fitnesse/authentication/SecurePageOperation.java
@@ -10,7 +10,7 @@
public abstract class SecurePageOperation implements SecureOperation {
protected abstract String getSecurityMode();
- public boolean shouldAuthenticate(FitNesseContext context, Request request) throws Exception {
+ public boolean shouldAuthenticate(FitNesseContext context, Request request) {
WikiPagePath path = PathParser.parse(request.getResource());
PageCrawler crawler = context.root.getPageCrawler();
WikiPage page = crawler.getPage(path, new MockingPageCrawler());
View
1  src/fitnesse/components/Logger.java
@@ -13,6 +13,7 @@
import java.util.Calendar;
import java.util.GregorianCalendar;
+// TODO: Convert to java.util.logging.Formatter
public class Logger {
private File directory;
View
31 src/fitnesse/fixtures/PageCreator.java
@@ -7,31 +7,24 @@
import fit.ColumnFixture;
import fitnesse.wiki.*;
-public class
- PageCreator extends ColumnFixture {
+public class PageCreator extends ColumnFixture {
public String pageName;
public String pageContents;
public String pageAttributes = "";
public boolean valid() throws Exception {
- try {
- if (pageContents != null) {
- pageContents = pageContents.replaceAll("<br>", "\n");
- pageContents = pageContents.replaceAll("<br/>", "\n");
- }
- WikiPage root = FitnesseFixtureContext.root;
- WikiPagePath pagePath = PathParser.parse(pageName);
- WikiPage thePage = WikiPageUtil.addPage(root, pagePath, pageContents);
- if (!"".equals(pageAttributes)) {
- PageData data = thePage.getData();
- setAttributes(data);
- thePage.commit(data);
- setPageAttributes("");
- }
+ if (pageContents != null) {
+ pageContents = pageContents.replaceAll("<br>", "\n");
+ pageContents = pageContents.replaceAll("<br/>", "\n");
}
- catch (Exception e) {
- e.printStackTrace();
- return false;
+ WikiPage root = FitnesseFixtureContext.root;
+ WikiPagePath pagePath = PathParser.parse(pageName);
+ WikiPage thePage = WikiPageUtil.addPage(root, pagePath, pageContents);
+ if (!"".equals(pageAttributes)) {
+ PageData data = thePage.getData();
+ setAttributes(data);
+ thePage.commit(data);
+ setPageAttributes("");
}
return true;
}
View
3  src/fitnesse/http/UploadedFile.java
@@ -3,6 +3,8 @@
package fitnesse.http;
import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import util.FileUtil;
@@ -34,7 +36,6 @@ public String toString() {
return "name : " + getName() + "; type : " + getType() + "; content : " + FileUtil.getFileContent(file);
}
catch (Exception e) {
- e.printStackTrace();
return e.toString();
}
}
View
7 src/fitnesse/junit/PrintTestListener.java
@@ -1,6 +1,7 @@
package fitnesse.junit;
import java.io.Closeable;
+import java.util.logging.Logger;
import fitnesse.testrunner.WikiTestPage;
import fitnesse.testsystems.Assertion;
@@ -14,12 +15,14 @@
import util.TimeMeasurement;
public class PrintTestListener implements TestSystemListener<WikiTestPage>, Closeable {
+ private final static Logger LOG = Logger.getLogger(PrintTestListener.class.getName());
+
private TimeMeasurement timeMeasurement;
private TimeMeasurement totalTimeMeasurement = new TimeMeasurement().start();
@Override
public void close() {
- System.out.println("--complete: " + totalTimeMeasurement.elapsedSeconds() + " seconds--");
+ LOG.info("--complete: " + totalTimeMeasurement.elapsedSeconds() + " seconds--");
}
@Override
@@ -29,7 +32,7 @@ public void testStarted(WikiTestPage test) {
@Override
public void testComplete(WikiTestPage test, TestSummary testSummary) {
- System.out.println(new WikiPagePath(test.getSourcePage()).toString() + " r " + testSummary.right + " w "
+ LOG.info(new WikiPagePath(test.getSourcePage()).toString() + " r " + testSummary.right + " w "
+ testSummary.wrong + " " + testSummary.exceptions
+ " " + timeMeasurement.elapsedSeconds() + " seconds");
}
View
2  src/fitnesse/junit/TestHelper.java
@@ -1,6 +1,6 @@
package fitnesse.junit;
-import fitnesse.Arguments;
+import fitnesseMain.Arguments;
import fitnesse.reporting.JavaFormatter;
import fitnesse.testsystems.TestSummary;
import fitnesse.testsystems.TestSystemListener;
View
50 src/fitnesse/logging/LogFormatter.java
@@ -0,0 +1,50 @@
+package fitnesse.logging;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+/**
+ * Java logging formatter.
+ */
+public class LogFormatter extends Formatter {
+
+ private static final String ENDL = System.getProperty("line.separator");
+
+ public LogFormatter() {
+ super();
+ }
+
+ @Override
+ public String format(LogRecord logRecord) {
+ StringBuilder builder = new StringBuilder(128);
+ Throwable thrown = logRecord.getThrown();
+
+ if (atLeastWarningLevel(logRecord)) {
+ builder.append(logRecord.getLevel().getName())
+ .append(": ");
+ }
+ builder.append(logRecord.getMessage());
+ if (thrown != null) {
+ builder.append(" [")
+ .append(thrown.getMessage())
+ .append("]");
+ }
+ builder.append(ENDL);
+
+ if (thrown != null && atLeastWarningLevel(logRecord)) {
+ StringWriter writer = new StringWriter();
+ thrown.printStackTrace(new PrintWriter(writer));
+ builder.append(writer.toString());
+ }
+ return builder.toString();
+ }
+
+ private boolean atLeastWarningLevel(LogRecord logRecord) {
+ return logRecord.getLevel().intValue() > Level.INFO.intValue();
+ }
+
+}
View
61 src/fitnesse/logging/LogFormatterTest.java
@@ -0,0 +1,61 @@
+package fitnesse.logging;
+
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.*;
+
+public class LogFormatterTest {
+
+ @Test
+ public void logLine() {
+ LogRecord logRecord = new LogRecord(Level.INFO, "message");
+ logRecord.setLoggerName("MyLogger");
+
+ assertEquals("message" + System.getProperty("line.separator"), new LogFormatter().format(logRecord));
+ }
+
+ @Test
+ public void logWarningLine() {
+ LogRecord logRecord = new LogRecord(Level.WARNING, "message");
+ logRecord.setLoggerName("MyLogger");
+
+ assertEquals("WARNING: message" + System.getProperty("line.separator"), new LogFormatter().format(logRecord));
+ }
+
+ @Test
+ public void logSevereLine() {
+ LogRecord logRecord = new LogRecord(Level.SEVERE, "message");
+ logRecord.setLoggerName("MyLogger");
+
+ assertEquals("SEVERE: message" + System.getProperty("line.separator"), new LogFormatter().format(logRecord));
+ }
+
+ @Test
+ public void logShouldLogExceptions() {
+ LogRecord logRecord = new LogRecord(Level.WARNING, "message");
+ logRecord.setLoggerName("MyLogger");
+ logRecord.setThrown(new RuntimeException(new IllegalArgumentException("Something went wrong here")));
+
+ String logOutput = new LogFormatter().format(logRecord);
+ assertTrue(logOutput, logOutput.contains("WARNING: message [java.lang.IllegalArgumentException: Something went wrong here]" + System.getProperty("line.separator")));
+ assertTrue(logOutput, logOutput.contains("at fitnesse.logging.LogFormatterTest.logShouldLogExceptions"));
+
+ }
+
+ @Test
+ public void logShouldNotLogExceptionsAtInfoLevel() {
+ LogRecord logRecord = new LogRecord(Level.WARNING, "message");
+ logRecord.setLoggerName("MyLogger");
+ logRecord.setThrown(new RuntimeException(new IllegalArgumentException("Something went wrong here")));
+
+ String logOutput = new LogFormatter().format(logRecord);
+ assertTrue(logOutput, logOutput.contains("WARNING: message [java.lang.IllegalArgumentException: Something went wrong here]" + System.getProperty("line.separator")));
+ assertFalse(logOutput, logOutput.contains("at fitnesse.logging.LogFormatterTest.logShouldLogExceptions"));
+
+ }
+
+}
View
7 src/fitnesse/reporting/BaseFormatter.java
@@ -13,8 +13,11 @@
import java.io.Closeable;
import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public abstract class BaseFormatter implements TestSystemListener<WikiTestPage>, Closeable {
+ protected final Logger LOG = Logger.getLogger(getClass().getName());
protected WikiPage page = null;
protected FitNesseContext context;
@@ -41,8 +44,8 @@ protected WikiPage getPage() {
public void errorOccurred(Throwable cause) {
try {
close();
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
+ LOG.log(Level.WARNING, "Unable to close formatter after error occurred", e);
}
}
View
5 src/fitnesse/reporting/XmlFormatter.java
@@ -24,6 +24,7 @@
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
+import java.util.logging.Level;
public class XmlFormatter extends BaseFormatter {
public interface WriterFactory {
@@ -89,7 +90,7 @@ public void testAssertionVerified(Assertion assertion, TestResult testResult) {
expectationResult.row = Integer.toString(cell.getRow());
}
} catch (Throwable e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to process assertion " + assertion + " with test result " + testResult, e);
}
}
@@ -111,7 +112,7 @@ public void testExceptionOccurred(Assertion assertion, ExceptionResult exception
expectationResult.evaluationMessage = exceptionResult.getMessage();
expectationResult.status = exceptionResult.getExecutionResult().toString();
} catch (Throwable e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to process assertion " + assertion + " with exception result " + exceptionResult, e);
}
}
View
6 src/fitnesse/reporting/history/MostRecentPageHistoryReader.java
@@ -2,10 +2,13 @@
import java.io.File;
import java.text.ParseException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.reporting.TestResultRecord;
public class MostRecentPageHistoryReader extends PageHistoryReader {
+ private final static Logger LOG = Logger.getLogger(MostRecentPageHistoryReader.class.getName());
TestResultRecord mostRecentRecord = null;
File directory = null;
@@ -18,8 +21,7 @@ public TestResultRecord findMostRecentTestRun() {
try {
readHistoryFromPageDirectory(directory);
} catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to read history from page directory", e);
}
return mostRecentRecord;
}
View
7 src/fitnesse/responders/ChunkingResponder.java
@@ -14,8 +14,12 @@
import fitnesse.wiki.WikiPagePath;
import java.net.SocketException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public abstract class ChunkingResponder implements Responder, ChunkedDataProvider {
+ private final Logger LOG = Logger.getLogger(ChunkingResponder.class.getName());
+
protected WikiPage root;
public WikiPage page;
protected WikiPagePath path;
@@ -66,8 +70,7 @@ public void startSending() {
doSending();
}
catch (SocketException e) {
- System.out.println("Socket Exception at: " + System.currentTimeMillis());
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Socket Exception at: " + System.currentTimeMillis(), e);
// normal. someone stopped the request.
}
catch (Exception e) {
View
6 src/fitnesse/responders/ImportAndViewResponder.java
@@ -12,8 +12,12 @@
import fitnesse.wiki.*;
import java.net.MalformedURLException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class ImportAndViewResponder implements SecureResponder, WikiImporterClient {
+ private final Logger LOG = Logger.getLogger(ImportAndViewResponder.class.getName());
+
private WikiPage page;
public Response makeResponse(FitNesseContext context, Request request) throws MalformedURLException {
@@ -56,7 +60,7 @@ public void pageImported(WikiPage localPage) {
}
public void pageImportError(WikiPage localPage, Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Page import error", e);
}
public SecureOperation getSecureOperation() {
View
6 src/fitnesse/responders/ResponderFactory.java
@@ -6,6 +6,8 @@
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import util.StringUtil;
import fitnesse.Responder;
@@ -44,6 +46,8 @@
import fitnesse.wikitext.parser.WikiWordPath;
public class ResponderFactory {
+ private final static Logger LOG = Logger.getLogger(ResponderFactory.class.getName());
+
private final String rootPath;
private final Map<String, Class<?>> responderMap;
@@ -149,7 +153,7 @@ private Responder lookupResponder(String responderKey)
try {
return newResponderInstance(responderClass);
} catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to instantiate responder " + responderKey, e);
throw new InstantiationException("Unable to instantiate responder " + responderKey);
}
}
View
7 src/fitnesse/responders/ShutdownResponder.java
@@ -2,6 +2,9 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.responders;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import fitnesse.FitNesse;
import fitnesse.FitNesseContext;
import fitnesse.authentication.AlwaysSecureOperation;
@@ -14,6 +17,8 @@
import fitnesse.html.template.PageTitle;
public class ShutdownResponder implements SecureResponder {
+ private final static Logger LOG = Logger.getLogger(ShutdownResponder.class.getName());
+
public Response makeResponse(FitNesseContext context, Request request) {
SimpleResponse response = new SimpleResponse();
@@ -30,7 +35,7 @@ public void run() {
FitNesse.FITNESSE_INSTANCE.stop();
}
catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Error while stopping FitNesse", e);
}
}
};
View
10 src/fitnesse/responders/WikiImportTestEventListener.java
@@ -2,6 +2,9 @@
// Released under the terms of the CPL Common Public License version 1.0.
package fitnesse.responders;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
import fitnesse.responders.run.SuiteResponder;
import fitnesse.responders.run.TestEventListener;
import fitnesse.responders.run.TestResponder;
@@ -10,6 +13,8 @@
import fitnesse.wiki.WikiPage;
public class WikiImportTestEventListener implements TestEventListener {
+ private static final Logger LOG = Logger.getLogger(WikiImportTestEventListener.class.getName());
+
public static void register() {
TestResponder.registerListener(new WikiImportTestEventListener(new WikiImporterFactory()));
}
@@ -96,10 +101,7 @@ public void pageImported(WikiPage localPage) {
public void pageImportError(WikiPage localPage, Exception e) {
errorOccured = true;
- System.out.println("Exception while importing \"local page\": " + localPage.getName() + ", exception: " + e.getMessage());
- if (e.getCause() != null)
- System.out.println(" cause: " + e.getCause().getMessage());
- e.printStackTrace(System.out);
+ LOG.log(Level.WARNING, "Exception while importing \"local page\": " + localPage.getName(), e);
testResponder.addToResponse(e.toString());
}
}
View
2  src/fitnesse/responders/WikiImportingResponderTest.java
@@ -155,8 +155,6 @@ public void testHtmlOfMakeResponse() throws IOException {
sender.doSending(response);
String content = sender.sentData();
- System.out.println(content);
-
assertSubString("<html>", content);
assertSubString("Wiki Import", content);
View
3  src/fitnesse/responders/run/TestResultFormattingResponder.java
@@ -34,7 +34,6 @@
public Response makeResponse(FitNesseContext context, Request request) throws Exception {
init(context, request);
- System.out.println("TestResultFormattingResponder");
String results = (String) request.getInput("results");
byte[] bytes = results.getBytes("UTF-8");
processResults(new ByteArrayInputStream(bytes));
@@ -47,7 +46,7 @@ public Response makeResponse(FitNesseContext context, Request request) throws Ex
public void init(FitNesseContext context, Request request) throws IOException {
this.context = context;
baseUrl = (String) request.getHeader("Host");
- rootPath = (String) request.getResource();
+ rootPath = request.getResource();
formatter = makeFormatter(request);
}
View
1  src/fitnesse/responders/versions/VersionComparerTest.java
@@ -29,7 +29,6 @@ public void testSimpleCompare() {
@Test
public void testPadsNonDifferentLinesWithSpaces() {
comparer.compare("1", originalContent, "2", revisedContent);
- System.out.println(StringUtil.join(comparer.getDifferences(), "\n"));
assertSubString(" First line in content", StringUtil.join(comparer.getDifferences(), "\n"));
assertSubString(" Last line in content.", StringUtil.join(comparer.getDifferences(), "\n"));
}
View
7 src/fitnesse/schedule/ScheduleImpl.java
@@ -5,10 +5,14 @@
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import util.Clock;
public class ScheduleImpl implements Schedule, Runnable {
+ private final static Logger LOG = Logger.getLogger(ScheduleImpl.class.getName());
+
private long delay;
private Thread thread;
private boolean running;
@@ -44,6 +48,7 @@ public void run() {
}
}
catch (Exception e) {
+ LOG.log(Level.FINER, "Error running scheduled loop", e);
}
}
@@ -62,7 +67,7 @@ private void runItem(ScheduleItem item, long time) throws Exception {
item.run(time);
}
catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Error running scheduled item " + item, e);
}
}
}
View
2  src/fitnesse/slim/test/TestSlim.java
@@ -259,12 +259,10 @@ public String concatenateThreeArgs(String first, String second, String third) {
}
public void setMap(Map<String, String> map) {
- System.out.println("set map = " + map);
this.map = map;
}
public Map<String, String> getMap() {
- System.out.println("got map = " + map);
return map;
}
View
18 src/fitnesse/socketservice/SocketService.java
@@ -8,8 +8,12 @@
import java.net.Socket;
import java.net.SocketException;
import java.util.LinkedList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class SocketService {
+ private static final Logger LOG = Logger.getLogger(SocketService.class.getName());
+
private ServerSocket serverSocket = null;
private Thread serviceThread = null;
private volatile boolean running = false;
@@ -31,14 +35,7 @@ public void run() {
}
private ServerSocket tryCreateServerSocket(int port) throws IOException {
- ServerSocket socket;
- try {
- socket = new ServerSocket(port);
- } catch (BindException e) {
- System.out.println("Bind exception on port = " + port);
- throw e;
- }
- return socket;
+ return new ServerSocket(port);
}
public void close() throws IOException {
@@ -49,7 +46,7 @@ public void close() throws IOException {
serviceThread.join();
waitForServerThreads();
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Thread joining interrupted", e);
}
}
@@ -66,8 +63,7 @@ private void serviceThread() {
Socket s = serverSocket.accept();
startServerThread(s);
} catch (java.lang.OutOfMemoryError e) {
- System.err.println("Can't create new thread. Out of Memory. Aborting");
- e.printStackTrace();
+ LOG.log(Level.SEVERE, "Can't create new thread. Out of Memory. Aborting.", e);
System.exit(99);
} catch (SocketException sox) {
running = false;// do nothing
View
5 src/fitnesse/testrunner/MultipleTestsRunner.java
@@ -12,8 +12,11 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class MultipleTestsRunner implements TestSystemListener<WikiTestPage>, Stoppable {
+ public static final Logger LOG = Logger.getLogger(MultipleTestsRunner.class.getName());
private final CompositeFormatter formatters;
private final FitNesseContext fitNesseContext;
@@ -213,7 +216,7 @@ public void stop() {
try {
testSystemGroup.kill();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to stop test systems", e);
}
}
}
View
5 src/fitnesse/testrunner/RunningTestingTracker.java
@@ -3,10 +3,13 @@
package fitnesse.testrunner;
import java.util.HashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.testrunner.Stoppable;
public class RunningTestingTracker {
+ public static final Logger LOG = Logger.getLogger(RunningTestingTracker.class.getName());
private HashMap<String, Stoppable> processes = new HashMap<String, Stoppable>();
private int nextTicketNumber = 1;
@@ -51,7 +54,7 @@ private void stopProcess(Stoppable process) {
try {
process.stop();
} catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to stop test system", e);
}
}
View
5 src/fitnesse/testrunner/SuiteContentsFinder.java
@@ -5,8 +5,11 @@
import fitnesse.wiki.*;
import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class SuiteContentsFinder {
+ public static final Logger LOG = Logger.getLogger(SuiteContentsFinder.class.getName());
private final WikiPage pageToRun;
private final WikiPage wikiRootPage;
@@ -71,7 +74,7 @@ public int compare(WikiPage p1, WikiPage p2) {
return path1.compareTo(path2);
}
catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to compare " + p1 + " and " + p2, e);
return 0;
}
}
View
6 src/fitnesse/testrunner/SuiteFilter.java
@@ -6,6 +6,8 @@
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.wiki.PageCrawler;
import fitnesse.wiki.PageData;
@@ -14,6 +16,8 @@
import util.StringUtil;
public class SuiteFilter {
+ public static final Logger LOG = Logger.getLogger(SuiteFilter.class.getName());
+
final private SuiteTagMatcher notMatchTags;
final private SuiteTagMatcher matchTags;
final private boolean andStrategy;
@@ -145,7 +149,7 @@ private String getTestTags(WikiPage context) {
try {
return context.getData().getAttribute(PageData.PropertySUITES);
} catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to retrieve tags for page " + context, e);
return null;
}
}
View
11 src/fitnesse/testsystems/CommandRunner.java
@@ -11,10 +11,14 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import util.TimeMeasurement;
public class CommandRunner {
+ private static final Logger LOG = Logger.getLogger(CommandRunner.class.getName());
+
private Process process;
private String input = "";
protected List<Throwable> exceptions = new ArrayList<Throwable>();
@@ -85,9 +89,9 @@ private void waitForDeathOf(Process process) {
Thread.sleep(timeStep);
}
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOG.log(Level.FINE, "Wait for death of process " + process + " interrupted", e);
}
- System.err.println("Could not detect death of command line test runner.");
+ LOG.warning("Could not detect death of command line test runner.");
}
private boolean isDead(Process process) throws InterruptedException {
@@ -159,8 +163,7 @@ protected void sendInput(OutputStream stdin) throws IOException {
try {
stdin.close();
} catch (IOException e) {
- // TODO: log at debug level
- e.printStackTrace();
+ LOG.log(Level.FINE, "Failed to close output stream", e);
}
}
}
View
7 src/fitnesse/testsystems/fit/FitClient.java
@@ -5,6 +5,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fit.Counts;
import fit.FitProtocol;
@@ -12,6 +14,7 @@
import util.StreamReader;
public class FitClient {
+ private static final Logger LOG = Logger.getLogger(FitClient.class.getName());
private FitClientListener listener;
private Socket fitSocket;
@@ -56,7 +59,7 @@ public void join() {
try {
fitListeningThread.join();
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOG.log(Level.FINE, "Wait for join of listening thread interrupted", e);
}
}
@@ -100,7 +103,7 @@ private void shortSleep() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOG.log(Level.FINE, "sleep interrupted", e);
}
}
View
7 src/fitnesse/testsystems/fit/FitSocketReceiver.java
@@ -5,10 +5,14 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.http.Request;
public class FitSocketReceiver {
+ private static final Logger LOG = Logger.getLogger(FitSocketReceiver.class.getName());
+
public static final int DEFAULT_SOCKET = 9123;
public ServerSocket serverSocket;
@@ -36,9 +40,10 @@ public void run() {
dealSocket(ticket);
}
catch (SocketException se) {
+ LOG.log(Level.FINE, "Socket exception", se);
}
catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Failed to receive socket", e);
}
}
}.start();
View
6 src/fitnesse/testsystems/fit/SimpleSocketDoner.java
@@ -4,10 +4,14 @@
import java.io.IOException;
import java.net.Socket;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.util.MockSocket;
public class SimpleSocketDoner implements SocketDoner {
+ private static final Logger LOG = Logger.getLogger(SimpleSocketDoner.class.getName());
+
public Socket socket;
public boolean finished = false;
@@ -28,7 +32,7 @@ public void finishedWithSocket() {
try {
socket.close();
} catch (IOException e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Failed to close socket", e);
}
}
}
View
6 src/fitnesse/testsystems/slim/HtmlTable.java
@@ -5,6 +5,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.regex.Pattern;
import fitnesse.testsystems.ExceptionResult;
@@ -25,6 +27,8 @@
import org.htmlparser.util.NodeList;
public class HtmlTable implements Table {
+ private static final Logger LOG = Logger.getLogger(HtmlTable.class.getName());
+
// Source: http://dev.w3.org/html5/markup/common-models.html
private final static Pattern HTML_PATTERN = Pattern.compile("^<(p|hr|pre|ul|ol|dl|div|h[1-6]|hgroup|address|" +
"blockquote|ins|del|object|map||video|audio|figure|table|fieldset|canvas|a|em|strong|small|mark|" +
@@ -192,7 +196,7 @@ private Tag newTag(Class<? extends Tag> klass) {
endTag.setParent(tag);
tag.setEndTag(endTag);
} catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to create tag from class " + klass, e);
}
return tag;
}
View
7 src/fitnesse/testsystems/slim/SlimClientBuilder.java
@@ -4,6 +4,8 @@
import java.net.ServerSocket;
import java.net.SocketException;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.slim.JavaSlimFactory;
import fitnesse.slim.SlimCommandRunningClient;
@@ -14,6 +16,7 @@
import fitnesse.testsystems.MockCommandRunner;
public class SlimClientBuilder extends ClientBuilder<SlimCommandRunningClient> {
+ private static final Logger LOG = Logger.getLogger(SlimClientBuilder.class.getName());
public static final String SLIM_PORT = "SLIM_PORT";
public static final String SLIM_HOST = "SLIM_HOST";
@@ -64,7 +67,7 @@ void createSlimService(String args) throws SocketException {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOG.log(Level.FINE, "Sleep interrupted", e);
}
}
@@ -77,7 +80,7 @@ private boolean tryCreateSlimService(String args) throws SocketException {
} catch (SocketException e) {
throw e;
} catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Unable to create SLiM service", e);
return false;
}
}
View
7 src/fitnesse/testsystems/slim/SlimTestSystem.java
@@ -9,6 +9,8 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.slim.SlimClient;
import fitnesse.slim.SlimError;
@@ -31,6 +33,8 @@
import static fitnesse.slim.SlimServer.*;
public abstract class SlimTestSystem implements TestSystem {
+ private static final Logger LOG = Logger.getLogger(SlimTestSystem.class.getName());
+
public static final SlimTable START_OF_TEST = null;
public static final SlimTable END_OF_TEST = null;
@@ -153,7 +157,6 @@ else if (tokens[0].equals(MALFORMED_INSTRUCTION))
public static String exceptionToString(Throwable e) {
StringWriter stringWriter = new StringWriter();
PrintWriter pw = new PrintWriter(stringWriter);
- e.printStackTrace(pw);
return SlimServer.EXCEPTION_TAG + stringWriter.toString();
}
@@ -202,7 +205,7 @@ protected void exceptionOccurred(Throwable e) {
try {
slimClient.kill();
} catch (IOException e1) {
- e1.printStackTrace();
+ LOG.log(Level.WARNING, "Failed to kill SLiM client", e);
}
ExecutionLog log = slimClient.getExecutionLog();
log.addException(e);
View
5 src/fitnesse/testsystems/slim/tables/SlimTableFactory.java
@@ -3,12 +3,15 @@
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import fitnesse.testsystems.slim.SlimTestContext;
import fitnesse.testsystems.slim.Table;
import fitnesse.testsystems.slim.tables.SlimTable.Disgracer;
public class SlimTableFactory {
+ private static final Logger LOG = Logger.getLogger(SlimTableFactory.class.getName());
private static final Map<String, Class<? extends SlimTable>> tableTypes;
@@ -74,7 +77,7 @@ private SlimTable newTableForType(Class<? extends SlimTable> tableClass,
Constructor<? extends SlimTable> constructor = tableClass.getConstructor(Table.class, String.class, SlimTestContext.class);
return constructor.newInstance(table, tableId, slimTestContext);
} catch (Exception e) {
- e.printStackTrace();
+ LOG.log(Level.WARNING, "Can not create new table instance for class " + tableClass, e);
return new SlimErrorTable(table, tableId, slimTestContext);
}
}
View
1  src/fitnesse/testutil/ClassTranslatePoint.java
@@ -7,6 +7,7 @@
import fit.TypeAdapter;
import fit.decorator.util.ClassDelegatePointParser;
+// Used in acceptance suite
public class ClassTranslatePoint extends TranslatePoint {
static {
TypeAdapter.registerParseDelegate(Point.class, ClassDelegatePointParser.class);
View
1  src/fitnesse/testutil/ObjectTranslatePoint.java
@@ -6,6 +6,7 @@
import fit.TypeAdapter;
+// Used in acceptance suite
public class ObjectTranslatePoint extends TranslatePoint {
public ObjectTranslatePoint() {
TypeAdapter.registerParseDelegate(Point.class, new ObjectDelegatePointParser());
View
1  src/fitnesse/testutil/PassFixture.java
@@ -5,6 +5,7 @@
import fit.Fixture;
import fit.Parse;
+// Used in acceptance suite
public class PassFixture extends Fixture {
public void doTable(Parse parse) {
right(parse);
View
1 