Skip to content

Commit bd79723

Browse files
committed
see #9710 - more debug messages
git-svn-id: http://josm.openstreetmap.de/svn/trunk@6852 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent dcb3772 commit bd79723

File tree

6 files changed

+51
-14
lines changed

6 files changed

+51
-14
lines changed

src/org/openstreetmap/josm/Main.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,26 @@ public static void trace(String msg) {
280280
}
281281
}
282282

283+
/**
284+
* Determines if debug log level is enabled.
285+
* Useful to avoid costly construction of debug messages when not enabled.
286+
* @return {@code true} if log level is at least debug, {@code false} otherwise
287+
* @since 6852
288+
*/
289+
public static boolean isDebugEnabled() {
290+
return logLevel >= 4;
291+
}
292+
293+
/**
294+
* Determines if trace log level is enabled.
295+
* Useful to avoid costly construction of trace messages when not enabled.
296+
* @return {@code true} if log level is at least trace, {@code false} otherwise
297+
* @since 6852
298+
*/
299+
public static boolean isTraceEnabled() {
300+
return logLevel >= 5;
301+
}
302+
283303
/**
284304
* Prints a formatted error message if logging is on. Calls {@link MessageFormat#format}
285305
* function to format text.
@@ -594,8 +614,10 @@ public Void call() throws Exception {
594614
}
595615
final long startTime = System.currentTimeMillis();
596616
initialize();
597-
final long elapsedTime = System.currentTimeMillis() - startTime;
598-
Main.debug(tr("{0} completed in {1}", name, Utils.getDurationString(elapsedTime)));
617+
if (isDebugEnabled()) {
618+
final long elapsedTime = System.currentTimeMillis() - startTime;
619+
Main.debug(tr("{0} completed in {1}", name, Utils.getDurationString(elapsedTime)));
620+
}
599621
return null;
600622
}
601623
}
@@ -659,13 +681,13 @@ public DataSet getCurrentDataSet() {
659681
if (!hasEditLayer()) return null;
660682
return getEditLayer().data;
661683
}
662-
684+
663685
/**
664686
* Replies the current selected primitives, from a end-user point of view.
665687
* It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
666688
* Indeed, if the user is currently in drawing mode, only the way currently being drawn is returned,
667689
* see {@link DrawAction#getInProgressSelection()}.
668-
*
690+
*
669691
* @return The current selected primitives, from a end-user point of view. Can be {@code null}.
670692
* @since 6546
671693
*/
@@ -1420,7 +1442,7 @@ public static boolean removeMapFrameListener(MapFrameListener listener) {
14201442
/**
14211443
* Adds a new network error that occur to give a hint about broken Internet connection.
14221444
* Do not use this method for errors known for sure thrown because of a bad proxy configuration.
1423-
*
1445+
*
14241446
* @param url The accessed URL that caused the error
14251447
* @param t The network error
14261448
* @return The previous error associated to the given resource, if any. Can be {@code null}
@@ -1440,7 +1462,7 @@ public static Throwable addNetworkError(URL url, Throwable t) {
14401462
/**
14411463
* Adds a new network error that occur to give a hint about broken Internet connection.
14421464
* Do not use this method for errors known for sure thrown because of a bad proxy configuration.
1443-
*
1465+
*
14441466
* @param url The accessed URL that caused the error
14451467
* @param t The network error
14461468
* @return The previous error associated to the given resource, if any. Can be {@code null}

src/org/openstreetmap/josm/data/validation/OsmValidator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ public static synchronized void initializeTests() {
307307
final long startTime = System.currentTimeMillis();
308308
initializeTests(getTests());
309309
testsInitialized = true;
310-
final long elapsedTime = System.currentTimeMillis() - startTime;
311-
Main.debug("Initializing validator tests completed in " + Utils.getDurationString(elapsedTime));
310+
if (Main.isDebugEnabled()) {
311+
final long elapsedTime = System.currentTimeMillis() - startTime;
312+
Main.debug("Initializing validator tests completed in " + Utils.getDurationString(elapsedTime));
313+
}
312314
}
313315
}
314316

src/org/openstreetmap/josm/gui/MapStatus.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ public void run() {
258258
try {
259259
wait(1000);
260260
} catch (InterruptedException e) {
261-
// Occurs frequently during JOSM shutdown, log set to debug only
262-
Main.debug("InterruptedException in "+MapStatus.class.getSimpleName());
261+
// Occurs frequently during JOSM shutdown, log set to trace only
262+
Main.trace("InterruptedException in "+MapStatus.class.getSimpleName());
263263
}
264264
ms.modifiers = mouseState.modifiers;
265265
ms.mousePos = mouseState.mousePos;

src/org/openstreetmap/josm/io/OsmApi.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,15 @@ private String sendRequest(String requestMethod, String urlSuffix,String request
686686
if (activeConnection.getHeaderField("Error") != null) {
687687
errorHeader = activeConnection.getHeaderField("Error");
688688
Main.error("Error header: " + errorHeader);
689-
} else if (retCode != 200 && responseBody.length()>0) {
689+
} else if (retCode != HttpURLConnection.HTTP_OK && responseBody.length()>0) {
690690
Main.error("Error body: " + responseBody);
691691
}
692692
activeConnection.disconnect();
693693

694+
if (Main.isDebugEnabled()) {
695+
Main.debug("RESPONSE: "+ activeConnection.getHeaderFields());
696+
}
697+
694698
errorHeader = errorHeader == null? null : errorHeader.trim();
695699
String errorBody = responseBody.length() == 0? null : responseBody.toString().trim();
696700
switch(retCode) {
@@ -722,9 +726,9 @@ private String sendRequest(String requestMethod, String urlSuffix,String request
722726
continue;
723727
}
724728
throw new OsmTransferException(e);
725-
} catch(IOException e){
729+
} catch(IOException e) {
726730
throw new OsmTransferException(e);
727-
} catch(OsmTransferCanceledException e){
731+
} catch(OsmTransferCanceledException e) {
728732
throw e;
729733
} catch(OsmTransferException e) {
730734
throw e;

src/org/openstreetmap/josm/io/OsmServerReader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressM
157157
throw ote;
158158
}
159159
try {
160-
Main.debug(activeConnection.getHeaderFields().toString());
160+
if (Main.isDebugEnabled()) {
161+
Main.debug("RESPONSE: "+activeConnection.getHeaderFields());
162+
}
161163
if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED)
162164
throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,null,null);
163165

src/org/openstreetmap/josm/tools/Utils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,13 @@ public static HttpURLConnection openHttpConnection(URL httpURL, boolean keepAliv
748748
if (!keepAlive) {
749749
connection.setRequestProperty("Connection", "close");
750750
}
751+
if (Main.isDebugEnabled()) {
752+
try {
753+
Main.debug("REQUEST: "+ connection.getRequestProperties());
754+
} catch (IllegalStateException e) {
755+
Main.warn(e);
756+
}
757+
}
751758
return connection;
752759
}
753760

0 commit comments

Comments
 (0)