Ignore:
Timestamp:
2017-08-22T22:26:32+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java

    r12382 r12620  
    5555     */
    5656    public static String explainOsmApiInitializationException(OsmApiInitializationException e) {
    57         Main.error(e);
     57        Logging.error(e);
    5858        return tr(
    5959                "<html>Failed to initialize communication with the OSM server {0}.<br>"
     
    7070     */
    7171    public static String explainMissingOAuthAccessTokenException(MissingOAuthAccessTokenException e) {
    72         Main.error(e);
     72        Logging.error(e);
    7373        return tr(
    7474                "<html>Failed to authenticate at the OSM server ''{0}''.<br>"
     
    143143     */
    144144    public static String explainPreconditionFailed(OsmApiException e) {
    145         Main.error(e);
     145        Logging.error(e);
    146146        Pair<OsmPrimitive, Collection<OsmPrimitive>> conflict = parsePreconditionFailed(e.getErrorHeader());
    147147        if (conflict != null) {
     
    262262     */
    263263    public static String explainFailedBasicAuthentication(OsmApiException e) {
    264         Main.error(e);
     264        Logging.error(e);
    265265        return tr("<html>"
    266266                + "Authentication at the OSM server with the username ''{0}'' failed.<br>"
     
    279279     */
    280280    public static String explainFailedOAuthAuthentication(OsmApiException e) {
    281         Main.error(e);
     281        Logging.error(e);
    282282        return tr("<html>"
    283283                + "Authentication at the OSM server with the OAuth token ''{0}'' failed.<br>"
     
    296296     */
    297297    public static String explainFailedAuthorisation(OsmApiException e) {
    298         Main.error(e);
     298        Logging.error(e);
    299299        String header = e.getErrorHeader();
    300300        String body = e.getErrorBody();
     
    334334     */
    335335    public static String explainFailedOAuthAuthorisation(OsmApiException e) {
    336         Main.error(e);
     336        Logging.error(e);
    337337        return tr("<html>"
    338338                + "Authorisation at the OSM server with the OAuth token ''{0}'' failed.<br>"
     
    353353     */
    354354    public static String explainClientTimeout(OsmApiException e) {
    355         Main.error(e);
     355        Logging.error(e);
    356356        return tr("<html>"
    357357                + "Communication with the OSM server ''{0}'' timed out. Please retry later."
     
    368368     */
    369369    public static String explainGenericOsmApiException(OsmApiException e) {
    370         Main.error(e);
     370        Logging.error(e);
    371371        return tr("<html>"
    372372                + "Communication with the OSM server ''{0}''failed. The server replied<br>"
     
    389389     */
    390390    public static String explainConflict(OsmApiException e) {
    391         Main.error(e);
     391        Logging.error(e);
    392392        String msg = e.getErrorHeader();
    393393        if (msg != null) {
     
    399399                    closeDate = DateUtils.newOsmApiDateTimeFormat().parse(m.group(2));
    400400                } catch (ParseException ex) {
    401                     Main.error(tr("Failed to parse date ''{0}'' replied by server.", m.group(2)));
    402                     Main.error(ex);
     401                    Logging.error(tr("Failed to parse date ''{0}'' replied by server.", m.group(2)));
     402                    Logging.error(ex);
    403403                }
    404404                if (closeDate == null) {
     
    437437     */
    438438    public static String explainChangesetClosedException(ChangesetClosedException e) {
    439         Main.error(e);
     439        Logging.error(e);
    440440        return tr(
    441441                "<html>Failed to upload to changeset <strong>{0}</strong><br>"
     
    457457            msg = e.toString();
    458458        }
    459         Main.error(e);
     459        Logging.error(e);
    460460        return Utils.escapeReservedCharactersHTML(msg);
    461461    }
     
    476476        } catch (MalformedURLException ex) {
    477477            // shouldn't happen
    478             Main.trace(ex);
     478            Logging.trace(ex);
    479479        }
    480480
     
    493493     */
    494494    public static String explainNestedSocketException(OsmTransferException e) {
    495         Main.error(e);
     495        Logging.error(e);
    496496        return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''.<br>"
    497497                + "Please check your internet connection.", e.getUrl())+"</html>";
     
    508508    public static String explainNestedIOException(OsmTransferException e) {
    509509        IOException ioe = getNestedException(e, IOException.class);
    510         Main.error(e);
     510        Logging.error(e);
    511511        return tr("<html>Failed to upload data to or download data from<br>" + "''{0}''<br>"
    512512                + "due to a problem with transferring data.<br>"
     
    525525    public static String explainNestedIllegalDataException(OsmTransferException e) {
    526526        IllegalDataException ide = getNestedException(e, IllegalDataException.class);
    527         Main.error(e);
     527        Logging.error(e);
    528528        return tr("<html>Failed to download data. "
    529529                + "Its format is either unsupported, ill-formed, and/or inconsistent.<br>"
     
    541541    public static String explainOfflineAccessException(OsmTransferException e) {
    542542        OfflineAccessException oae = getNestedException(e, OfflineAccessException.class);
    543         Main.error(e);
     543        Logging.error(e);
    544544        return tr("<html>Failed to download data.<br>"
    545545                + "<br>Details: {0}</html>", oae != null ? oae.getMessage() : "null");
     
    554554     */
    555555    public static String explainInternalServerError(OsmTransferException e) {
    556         Main.error(e);
     556        Logging.error(e);
    557557        return tr("<html>The OSM server<br>" + "''{0}''<br>" + "reported an internal server error.<br>"
    558558                + "This is most likely a temporary problem. Please try again later.", e.getUrl())+"</html>";
     
    576576            message += tr("<br>Error message(untranslated): {0}", errorHeader);
    577577        }
    578         Main.error(e);
     578        Logging.error(e);
    579579        return "<html>" + message + "</html>";
    580580    }
     
    588588     */
    589589    public static String explainBandwidthLimitExceeded(OsmApiException e) {
    590         Main.error(e);
     590        Logging.error(e);
    591591        // TODO: Write a proper error message
    592592        return explainGenericOsmApiException(e);
     
    605605                + "it. Please carefully check the server''s address ''{0}'' for typos.",
    606606                getUrlFromException(e));
    607         Main.error(e);
     607        Logging.error(e);
    608608        return "<html>" + message + "</html>";
    609609    }
     
    624624        } catch (MalformedURLException ex) {
    625625            // shouldn't happen
    626             Main.trace(e);
    627         }
    628 
    629         Main.error(e);
     626            Logging.trace(e);
     627        }
     628
     629        Logging.error(e);
    630630        return tr("<html>Failed to open a connection to the remote server<br>" + "''{0}''.<br>"
    631631                + "Host name ''{1}'' could not be resolved. <br>"
     
    719719     */
    720720    public static String explainException(Exception e) {
    721         Main.error(e);
     721        Logging.error(e);
    722722        if (e instanceof OsmTransferException) {
    723723            return explainOsmTransferException((OsmTransferException) e);
     
    732732                return new URL(e.getAccessedUrl()).getHost();
    733733            } catch (MalformedURLException e1) {
    734                 Main.warn(e1);
     734                Logging.warn(e1);
    735735            }
    736736        }
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r11745 r12620  
    4646            return readTime(metadata);
    4747        } catch (JpegProcessingException | IOException e) {
    48             Main.error(e);
     48            Logging.error(e);
    4949        }
    5050        return null;
     
    112112                        date.setTime(date.getTime() + (long) (TimeUnit.SECONDS.toMillis(1) * Double.parseDouble("0." + subSeconds)));
    113113                    } catch (NumberFormatException e) {
    114                         Main.warn("Failed parsing sub seconds from [{0}]", subSeconds);
    115                         Main.warn(e);
     114                        Logging.warn("Failed parsing sub seconds from [{0}]", subSeconds);
     115                        Logging.warn(e);
    116116                    }
    117117                }
     
    119119            }
    120120        } catch (UncheckedParseException e) {
    121             Main.error(e);
     121            Logging.error(e);
    122122        }
    123123        return null;
     
    146146            return dir == null ? null : dir.getInteger(ExifIFD0Directory.TAG_ORIENTATION);
    147147        } catch (JpegProcessingException | IOException e) {
    148             Main.error(e);
     148            Logging.error(e);
    149149        }
    150150        return null;
     
    163163            return readLatLon(dirGps);
    164164        } catch (JpegProcessingException | IOException | MetadataException e) {
    165             Main.error(e);
     165            Logging.error(e);
    166166        }
    167167        return null;
     
    197197            return readDirection(dirGps);
    198198        } catch (JpegProcessingException | IOException e) {
    199             Main.error(e);
     199            Logging.error(e);
    200200        }
    201201        return null;
     
    255255            return readSpeed(dirGps);
    256256        } catch (JpegProcessingException | IOException e) {
    257             Main.error(e);
     257            Logging.error(e);
    258258        }
    259259        return null;
     
    299299            return readElevation(dirGps);
    300300        } catch (JpegProcessingException | IOException e) {
    301             Main.error(e);
     301            Logging.error(e);
    302302        }
    303303        return null;
  • trunk/src/org/openstreetmap/josm/tools/GeoUrlToBounds.java

    r12382 r12620  
    4141                lat = Double.parseDouble(m.group("lat"));
    4242            } catch (NumberFormatException e) {
    43                 Main.warn(tr("URL does not contain valid {0}", tr("latitude")), e);
     43                Logging.warn(tr("URL does not contain valid {0}", tr("latitude")), e);
    4444                return null;
    4545            }
     
    4747                lon = Double.parseDouble(m.group("lon"));
    4848            } catch (NumberFormatException e) {
    49                 Main.warn(tr("URL does not contain valid {0}", tr("longitude")), e);
     49                Logging.warn(tr("URL does not contain valid {0}", tr("longitude")), e);
    5050                return null;
    5151            }
     
    5353                zoom = m.group("zoom") != null ? Integer.parseInt(m.group("zoom")) : 18;
    5454            } catch (NumberFormatException e) {
    55                 Main.warn(tr("URL does not contain valid {0}", tr("zoom")), e);
     55                Logging.warn(tr("URL does not contain valid {0}", tr("zoom")), e);
    5656                return null;
    5757            }
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r12382 r12620  
    932932            outerInner = MultipolygonBuilder.joinWays(multiPolygon);
    933933        } catch (MultipolygonBuilder.JoinedPolygonCreationException ex) {
    934             Main.trace(ex);
    935             Main.debug("Invalid multipolygon " + multiPolygon);
     934            Logging.trace(ex);
     935            Logging.debug("Invalid multipolygon " + multiPolygon);
    936936            return false;
    937937        }
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r12590 r12620  
    111111
    112112        if ("PUT".equals(requestMethod) || "POST".equals(requestMethod) || "DELETE".equals(requestMethod)) {
    113             Main.info("{0} {1} ({2}) ...", requestMethod, url, Utils.getSizeString(requestBody.length, Locale.getDefault()));
     113            Logging.info("{0} {1} ({2}) ...", requestMethod, url, Utils.getSizeString(requestBody.length, Locale.getDefault()));
    114114            connection.setFixedLengthStreamingMode(requestBody.length);
    115115            connection.setDoOutput(true);
     
    125125                connection.connect();
    126126                final boolean hasReason = reasonForRequest != null && !reasonForRequest.isEmpty();
    127                 Main.info("{0} {1}{2} -> {3}{4}",
     127                Logging.info("{0} {1}{2} -> {3}{4}",
    128128                        requestMethod, url, hasReason ? (" (" + reasonForRequest + ')') : "",
    129129                        connection.getResponseCode(),
     
    132132                                : ""
    133133                );
    134                 if (Main.isDebugEnabled()) {
    135                     Main.debug("RESPONSE: " + connection.getHeaderFields());
     134                if (Logging.isDebugEnabled()) {
     135                    Logging.debug("RESPONSE: {0}", connection.getHeaderFields());
    136136                }
    137137                if (DefaultAuthenticator.getInstance().isEnabled() && connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
     
    139139                }
    140140            } catch (IOException e) {
    141                 Main.info("{0} {1} -> !!!", requestMethod, url);
    142                 Main.warn(e);
     141                Logging.info("{0} {1} -> !!!", requestMethod, url);
     142                Logging.warn(e);
    143143                //noinspection ThrowableResultOfMethodCallIgnored
    144144                Main.addNetworkError(url, Utils.getRootCause(e));
     
    154154                    url = new URL(url, redirectLocation);
    155155                    maxRedirects--;
    156                     Main.info(tr("Download redirected to ''{0}''", redirectLocation));
     156                    Logging.info(tr("Download redirected to ''{0}''", redirectLocation));
    157157                    return connect();
    158158                } else if (maxRedirects == 0) {
     
    210210                    String content = this.fetchContent();
    211211                    if (content.isEmpty()) {
    212                         Main.debug("Server did not return any body");
     212                        Logging.debug("Server did not return any body");
    213213                    } else {
    214                         Main.debug("Response body: ");
    215                         Main.debug(this.fetchContent());
     214                        Logging.debug("Response body: ");
     215                        Logging.debug(this.fetchContent());
    216216                    }
    217217                } else {
    218                     Main.debug("Server returned content: {0} of length: {1}. Not printing.", contentType, this.getContentLength());
     218                    Logging.debug("Server returned content: {0} of length: {1}. Not printing.", contentType, this.getContentLength());
    219219                }
    220220            }
     
    283283                in = connection.getInputStream();
    284284            } catch (IOException ioe) {
    285                 Main.debug(ioe);
     285                Logging.debug(ioe);
    286286                in = Optional.ofNullable(connection.getErrorStream()).orElseGet(() -> new ByteArrayInputStream(new byte[]{}));
    287287            }
     
    291291            if (uncompress) {
    292292                final String contentType = getContentType();
    293                 Main.debug("Uncompressing input stream according to Content-Type header: {0}", contentType);
     293                Logging.debug("Uncompressing input stream according to Content-Type header: {0}", contentType);
    294294                compression = Compression.forContentType(contentType);
    295295            }
     
    299299                        contentDisposition != null ? contentDisposition : "");
    300300                if (matcher.find()) {
    301                     Main.debug("Uncompressing input stream according to Content-Disposition header: {0}", contentDisposition);
     301                    Logging.debug("Uncompressing input stream according to Content-Disposition header: {0}", contentDisposition);
    302302                    compression = Compression.byExtension(matcher.group(1));
    303303                }
     
    661661                Thread.sleep(100);
    662662            } catch (InterruptedException ex) {
    663                 Main.warn("InterruptedException in " + HttpClient.class + " during cancel");
     663                Logging.warn("InterruptedException in " + HttpClient.class + " during cancel");
    664664                Thread.currentThread().interrupt();
    665665            }
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r12537 r12620  
    487487        } catch (IOException e) {
    488488            // Ignore
    489             Main.trace(e);
     489            Logging.trace(e);
    490490        }
    491491    }
     
    517517        } catch (IOException e) {
    518518            // Ignore exception
    519             Main.trace(e);
     519            Logging.trace(e);
    520520        }
    521521        return false;
     
    643643            }
    644644        } catch (IOException e) {
    645             Main.trace(e);
     645            Logging.trace(e);
    646646            return false;
    647647        }
     
    670670            } else {
    671671                if (!"en".equals(l.getLanguage())) {
    672                     Main.info(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
     672                    Logging.info(tr("Unable to find translation for the locale {0}. Reverting to {1}.",
    673673                            LanguageInfo.getDisplayName(l), LanguageInfo.getDisplayName(Locale.getDefault())));
    674674                } else {
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r12524 r12620  
    642642            } else {
    643643                if (!suppressWarnings) {
    644                     Main.error(tr("Failed to locate image ''{0}''", name));
     644                    Logging.error(tr("Failed to locate image ''{0}''", name));
    645645                }
    646646                return null;
     
    917917                    img = read(Utils.fileToURL(cf.getFile()), false, false);
    918918                } catch (IOException e) {
    919                     Main.warn(e, "IOException while reading HTTP image:");
     919                    Logging.log(Logging.LEVEL_WARN, "IOException while reading HTTP image:", e);
    920920                }
    921921                return img == null ? null : new ImageResource(img);
     
    924924            }
    925925        } catch (IOException e) {
    926             Main.debug(e);
     926            Logging.debug(e);
    927927            return null;
    928928        }
     
    947947                    bytes = Utils.decodeUrl(data).getBytes(StandardCharsets.UTF_8);
    948948                } catch (IllegalArgumentException ex) {
    949                     Main.warn(ex, "Unable to decode URL data part: "+ex.getMessage() + " (" + data + ')');
     949                    Logging.log(Logging.LEVEL_WARN, "Unable to decode URL data part: "+ex.getMessage() + " (" + data + ')', ex);
    950950                    return null;
    951951                }
     
    960960                }
    961961                if (svg == null) {
    962                     Main.warn("Unable to process svg: "+s);
     962                    Logging.warn("Unable to process svg: "+s);
    963963                    return null;
    964964                }
     
    974974                    return img == null ? null : new ImageResource(img);
    975975                } catch (IOException e) {
    976                     Main.warn(e, "IOException while reading image:");
     976                    Logging.log(Logging.LEVEL_WARN, "IOException while reading image:", e);
    977977                }
    978978            }
     
    10591059                            img = read(new ByteArrayInputStream(buf), false, false);
    10601060                        } catch (IOException e) {
    1061                             Main.warn(e);
     1061                            Logging.warn(e);
    10621062                        }
    10631063                        return img == null ? null : new ImageResource(img);
     
    10681068            }
    10691069        } catch (IOException e) {
    1070             Main.warn(e, tr("Failed to handle zip file ''{0}''. Exception was: {1}", archive.getName(), e.toString()));
     1070            Logging.log(Logging.LEVEL_WARN, tr("Failed to handle zip file ''{0}''. Exception was: {1}", archive.getName(), e.toString()), e);
    10711071        }
    10721072        return null;
     
    10961096                // hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/dc4322602480/src/share/classes/com/sun/imageio/plugins/png/PNGImageReader.java#l656
    10971097                img = read(path, false, true);
    1098                 if (Main.isDebugEnabled() && isTransparencyForced(img)) {
    1099                     Main.debug("Transparency has been forced for image "+path.toExternalForm());
     1098                if (Logging.isDebugEnabled() && isTransparencyForced(img)) {
     1099                    Logging.debug("Transparency has been forced for image {0}", path);
    11001100                }
    11011101            } catch (IOException e) {
    1102                 Main.warn(e);
     1102                Logging.warn(e);
    11031103            }
    11041104            return img == null ? null : new ImageResource(img);
     
    11391139                        return u;
    11401140                } catch (SecurityException e) {
    1141                     Main.warn(e, tr(
     1141                    Logging.log(Logging.LEVEL_WARN, tr(
    11421142                            "Failed to access directory ''{0}'' for security reasons. Exception was: {1}",
    1143                             name, e.toString()));
     1143                            name, e.toString()), e);
    11441144                }
    11451145
     
    11541154                    return u;
    11551155            } catch (SecurityException e) {
    1156                 Main.warn(e, tr(
     1156                Logging.log(Logging.LEVEL_WARN, tr(
    11571157                        "Failed to access directory ''{0}'' for security reasons. Exception was: {1}", dir, e
    1158                         .toString()));
     1158                        .toString()), e);
    11591159            }
    11601160        }
     
    12261226            }
    12271227        } catch (SAXReturnException e) {
    1228             Main.trace(e);
     1228            Logging.trace(e);
    12291229            return e.getResult();
    12301230        } catch (IOException | SAXException | ParserConfigurationException e) {
    1231             Main.warn("Parsing " + base + fn + " failed:\n" + e);
     1231            Logging.warn("Parsing " + base + fn + " failed:\n" + e);
    12321232            return null;
    12331233        }
    1234         Main.warn("Parsing " + base + fn + " failed: Unexpected content.");
     1234        Logging.warn("Parsing " + base + fn + " failed: Unexpected content.");
    12351235        return null;
    12361236    }
     
    12511251        }
    12521252        if (GraphicsEnvironment.isHeadless()) {
    1253             if (Main.isDebugEnabled()) {
    1254                 Main.debug("Cursors are not available in headless mode. Returning null for '"+name+'\'');
    1255             }
     1253            Logging.debug("Cursors are not available in headless mode. Returning null for '{0}'", name);
    12561254            return null;
    12571255        }
     
    14651463     */
    14661464    public static BufferedImage createImageFromSvg(SVGDiagram svg, Dimension dim) {
    1467         if (Main.isTraceEnabled()) {
    1468             Main.trace(String.format("createImageFromSvg: %s %s", svg.getXMLBase(), dim));
     1465        if (Logging.isTraceEnabled()) {
     1466            Logging.trace("createImageFromSvg: {0} {1}", svg.getXMLBase(), dim);
    14691467        }
    14701468        float sourceWidth = svg.getWidth();
     
    15041502            }
    15051503        } catch (SVGException ex) {
    1506             Main.error(ex, "Unable to load svg:");
     1504            Logging.log(Logging.LEVEL_ERROR, "Unable to load svg:", ex);
    15071505            return null;
    15081506        }
     
    17241722                    bi = new BufferedImage(bi.getColorModel(), bi.getRaster(), bi.isAlphaPremultiplied(), properties);
    17251723                    if (enforceTransparency) {
    1726                         if (Main.isTraceEnabled()) {
    1727                             Main.trace("Enforcing image transparency of "+stream+" for "+color);
    1728                         }
     1724                        Logging.trace("Enforcing image transparency of {0} for {1}", stream, color);
    17291725                        bi = makeImageTransparent(bi, color);
    17301726                    }
     
    17341730            // On Windows, ComponentColorModel.getRGBComponent can fail with "UnsatisfiedLinkError: no awt in java.library.path", see #13973
    17351731            // Then it can leads to "NoClassDefFoundError: Could not initialize class sun.awt.image.ShortInterleavedRaster", see #15079
    1736             Main.error(e);
     1732            Logging.error(e);
    17371733        } finally {
    17381734            reader.dispose();
     
    17811777                                                return new Color(r, g, b);
    17821778                                            } else {
    1783                                                 Main.warn("Unable to translate TransparentColor '"+value+"' with color model "+model);
     1779                                                Logging.warn("Unable to translate TransparentColor '"+value+"' with color model "+model);
    17841780                                            }
    17851781                                        }
     
    17941790        } catch (IIOException | NumberFormatException e) {
    17951791            // JAI doesn't like some JPEG files with error "Inconsistent metadata read from stream" (see #10267)
    1796             Main.warn(e);
     1792            Logging.warn(e);
    17971793        }
    17981794        return null;
     
    18071803            return new Color(rgb[0], rgb[1], rgb[2]);
    18081804        } catch (IllegalArgumentException e) {
    1809             Main.error(e);
     1805            Logging.error(e);
    18101806            return null;
    18111807        }
  • trunk/src/org/openstreetmap/josm/tools/ImageWarp.java

    r11972 r12620  
    6363            this.stride = stride;
    6464            this.cache = new HashMap<>();
    65             this.consistencyTest = Main.isDebugEnabled();
     65            this.consistencyTest = Logging.isDebugEnabled();
    6666            if (consistencyTest) {
    6767                deletedRows = new HashSet<>();
  • trunk/src/org/openstreetmap/josm/tools/ListenerList.java

    r11224 r12620  
    200200        @Override
    201201        protected void failAdd(T listener) {
    202             Main.trace("Previous addition of the listener");
     202            Logging.trace("Previous addition of the listener");
    203203            dumpStack(listenersAdded.get(listener));
    204204            super.failAdd(listener);
     
    207207        @Override
    208208        protected void failRemove(T listener) {
    209             Main.trace("Previous removal of the listener");
     209            Logging.trace("Previous removal of the listener");
    210210            dumpStack(listenersRemoved.get(listener));
    211211            super.failRemove(listener);
     
    214214        private static void dumpStack(StackTraceElement ... stackTraceElements) {
    215215            if (stackTraceElements == null) {
    216                 Main.trace("  - (no trace recorded)");
     216                Logging.trace("  - (no trace recorded)");
    217217            } else {
    218218                Stream.of(stackTraceElements).limit(20).forEach(
    219                         e -> Main.trace(e.getClassName() + "." + e.getMethodName() + " line " + e.getLineNumber()));
     219                        e -> Logging.trace(e.getClassName() + "." + e.getMethodName() + " line " + e.getLineNumber()));
    220220            }
    221221        }
     
    242242     */
    243243    public static <T> ListenerList<T> create() {
    244         if (Main.isTraceEnabled()) {
     244        if (Logging.isTraceEnabled()) {
    245245            return new TracingListenerList<>();
    246246        } else {
  • trunk/src/org/openstreetmap/josm/tools/Logging.java

    r11624 r12620  
    113113
    114114    /**
     115     * Prints an error message for the given Throwable if logging is on.
     116     * @param t The throwable object causing the error.
     117     * @since 12620
     118     */
     119    public static void error(Throwable t) {
     120        logWithStackTrace(Logging.LEVEL_ERROR, t);
     121    }
     122
     123    /**
    115124     * Prints a warning message if logging is on.
    116125     * @param message The message to print.
     
    131140
    132141    /**
     142     * Prints a warning message for the given Throwable if logging is on.
     143     * @param t The throwable object causing the error.
     144     * @since 12620
     145     */
     146    public static void warn(Throwable t) {
     147        logWithStackTrace(Logging.LEVEL_WARN, t);
     148    }
     149
     150    /**
    133151     * Prints a info message if logging is on.
    134152     * @param message The message to print.
     
    149167
    150168    /**
     169     * Prints a info message for the given Throwable if logging is on.
     170     * @param t The throwable object causing the error.
     171     * @since 12620
     172     */
     173    public static void info(Throwable t) {
     174        logWithStackTrace(Logging.LEVEL_INFO, t);
     175    }
     176
     177    /**
    151178     * Prints a debug message if logging is on.
    152179     * @param message The message to print.
     
    167194
    168195    /**
     196     * Prints a debug message for the given Throwable if logging is on.
     197     * @param t The throwable object causing the error.
     198     * @since 12620
     199     */
     200    public static void debug(Throwable t) {
     201        logWithStackTrace(Logging.LEVEL_DEBUG, t);
     202    }
     203
     204    /**
    169205     * Prints a trace message if logging is on.
    170206     * @param message The message to print.
     
    185221
    186222    /**
    187      * Logs a throwable that happened.
     223     * Prints a trace message for the given Throwable if logging is on.
     224     * @param t The throwable object causing the error.
     225     * @since 12620
     226     */
     227    public static void trace(Throwable t) {
     228        logWithStackTrace(Logging.LEVEL_TRACE, t);
     229    }
     230
     231    /**
     232     * Logs a throwable that happened. The stack trace is not added to the log.
    188233     * @param level The level.
    189234     * @param t The throwable that should be logged.
     235     * @see #logWithStackTrace(Level, Throwable)
    190236     */
    191237    public static void log(Level level, Throwable t) {
     
    194240
    195241    /**
    196      * Logs a throwable that happened.
     242     * Logs a throwable that happened. The stack trace is not added to the log.
    197243     * @param level The level.
    198244     * @param message An additional error message
    199245     * @param t The throwable that caused the message
     246     * @see #logWithStackTrace(Level, String, Throwable)
    200247     */
    201248    public static void log(Level level, String message, Throwable t) {
     
    207254     * @param level The level.
    208255     * @param t The throwable that should be logged.
     256     * @see #log(Level, Throwable)
    209257     */
    210258    public static void logWithStackTrace(Level level, Throwable t) {
     
    217265     * @param message An additional error message
    218266     * @param t The throwable that should be logged.
     267     * @see #logWithStackTrace(Level, Throwable)
    219268     */
    220269    public static void logWithStackTrace(Level level, String message, Throwable t) {
     
    231280
    232281    private static void logPrivate(Level level, Supplier<String> supplier) {
    233         // all log methods immeadiately call one of the logPrivate methods.
     282        // all log methods immediately call one of the logPrivate methods.
    234283        if (LOGGER.isLoggable(level)) {
    235284            StackTraceElement callingMethod = BugReport.getCallingMethod(1, Logging.class.getName(), name -> !"logPrivate".equals(name));
     
    242291     *
    243292     * For formatting text, you should use the {@link #debug(String, Object...)} message
    244      * @param level A lvele constant. You can e.g. use {@link Logging#LEVEL_ERROR}
    245      * @return <code>true</code> if debug is enabled.
     293     * @param level A level constant. You can e.g. use {@link Logging#LEVEL_ERROR}
     294     * @return <code>true</code> if log level is enabled.
    246295     */
    247296    public static boolean isLoggingEnabled(Level level) {
    248297        return LOGGER.isLoggable(level);
     298    }
     299
     300    /**
     301     * Determines if debug log level is enabled.
     302     * Useful to avoid costly construction of debug messages when not enabled.
     303     * @return {@code true} if log level is at least debug, {@code false} otherwise
     304     * @since 12620
     305     */
     306    public static boolean isDebugEnabled() {
     307        return isLoggingEnabled(Logging.LEVEL_DEBUG);
     308    }
     309
     310    /**
     311     * Determines if trace log level is enabled.
     312     * Useful to avoid costly construction of trace messages when not enabled.
     313     * @return {@code true} if log level is at least trace, {@code false} otherwise
     314     * @since 12620
     315     */
     316    public static boolean isTraceEnabled() {
     317        return isLoggingEnabled(Logging.LEVEL_TRACE);
    249318    }
    250319
  • trunk/src/org/openstreetmap/josm/tools/MemoryManager.java

    r10717 r12620  
    5252                throw new IllegalArgumentException("Factory did not return a content element.");
    5353            }
    54             Main.info(MessageFormat.format("Allocate for {0}: {1} MB of memory. Available: {2} MB.",
     54            Logging.info(MessageFormat.format("Allocate for {0}: {1} MB of memory. Available: {2} MB.",
    5555                    name, maxBytes / 1024 / 1024, getAvailableMemory() / 1024 / 1024));
    5656            MemoryHandle<T> handle = new ManualFreeMemoryHandle<>(name, content, maxBytes);
  • trunk/src/org/openstreetmap/josm/tools/OpenBrowser.java

    r11156 r12620  
    4141        CheckParameterUtil.ensureParameterNotNull(uri, "uri");
    4242
    43         Main.info(tr("Opening URL: {0}", uri));
     43        Logging.info(tr("Opening URL: {0}", uri));
    4444
    4545        if (Desktop.isDesktopSupported()) {
     
    5959                        // Workaround for KDE (Desktop API is severely flawed)
    6060                        // see https://bugs.openjdk.java.net/browse/JDK-6486393
    61                         Main.warn(e, "Desktop class failed. Platform dependent fall back for open url in browser.");
     61                        Logging.log(Logging.LEVEL_WARN, "Desktop class failed. Platform dependent fall back for open url in browser.", e);
    6262                        displayUrlFallback(uri);
    6363                    }
    6464                }
    6565            } catch (IOException e) {
    66                 Main.warn(e);
     66                Logging.warn(e);
    6767                return e.getMessage();
    6868            }
    6969        } else {
    7070            try {
    71                 Main.warn("Desktop class is not supported. Platform dependent fall back for open url in browser.");
     71                Logging.warn("Desktop class is not supported. Platform dependent fall back for open url in browser.");
    7272                displayUrlFallback(uri);
    7373            } catch (IOException e) {
    74                 Main.debug(e);
     74                Logging.debug(e);
    7575                return e.getMessage();
    7676            }
     
    9191            return displayUrl(new URI(url));
    9292        } catch (URISyntaxException e) {
    93             Main.debug(e);
     93            Logging.debug(e);
    9494            return e.getMessage();
    9595        }
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r12382 r12620  
    4242            }
    4343        } catch (IllegalArgumentException ex) {
    44             Main.error(ex);
     44            Logging.error(ex);
    4545        }
    4646        Bounds b = parseShortLink(url);
     
    8282            }
    8383        } catch (IllegalArgumentException | ArrayIndexOutOfBoundsException ex) {
    84             Main.error(ex, url);
     84            Logging.log(Logging.LEVEL_ERROR, url, ex);
    8585        }
    8686        return b;
     
    102102        String[] parts = coordPart.split("/");
    103103        if (parts.length < 3) {
    104             Main.warn(tr("URL does not contain {0}/{1}/{2}", tr("zoom"), tr("latitude"), tr("longitude")));
     104            Logging.warn(tr("URL does not contain {0}/{1}/{2}", tr("zoom"), tr("latitude"), tr("longitude")));
    105105            return null;
    106106        }
     
    109109            zoom = Integer.parseInt(parts[0]);
    110110        } catch (NumberFormatException e) {
    111             Main.warn(tr("URL does not contain valid {0}", tr("zoom")), e);
     111            Logging.warn(tr("URL does not contain valid {0}", tr("zoom")), e);
    112112            return null;
    113113        }
     
    116116            lat = Double.parseDouble(parts[1]);
    117117        } catch (NumberFormatException e) {
    118             Main.warn(tr("URL does not contain valid {0}", tr("latitude")), e);
     118            Logging.warn(tr("URL does not contain valid {0}", tr("latitude")), e);
    119119            return null;
    120120        }
     
    122122            lon = Double.parseDouble(parts[2]);
    123123        } catch (NumberFormatException e) {
    124             Main.warn(tr("URL does not contain valid {0}", tr("longitude")), e);
     124            Logging.warn(tr("URL does not contain valid {0}", tr("longitude")), e);
    125125            return null;
    126126        }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHook.java

    r12320 r12620  
    281281                    openUrl(url);
    282282                } catch (IOException e) {
    283                     Main.warn(e);
     283                    Logging.warn(e);
    284284                }
    285285            }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r12537 r12620  
    7575        } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    7676            // We'll just ignore this for now. The user will still be able to close JOSM by closing all its windows.
    77             Main.warn("Failed to register with OSX: " + ex);
     77            Logging.warn("Failed to register with OSX: " + ex);
    7878        }
    7979        checkExpiredJava();
     
    113113            return Class.forName("com.apple.eawt."+className);
    114114        } catch (ClassNotFoundException e) {
    115             Main.trace(e);
     115            Logging.trace(e);
    116116            // Java 9 handlers
    117117            return Class.forName("java.awt.desktop."+className);
     
    132132                    Window.class, boolean.class).invoke(eawtFullScreenUtilities, window, Boolean.TRUE);
    133133        } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
    134             Main.warn("Failed to register with OSX: " + e);
     134            Logging.warn("Failed to register with OSX: " + e);
    135135        }
    136136    }
     
    139139    @Override
    140140    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    141         if (Main.isDebugEnabled()) {
    142             Main.debug("OSX handler: "+method.getName()+" - "+Arrays.toString(args));
     141        if (Logging.isDebugEnabled()) {
     142            Logging.debug("OSX handler: {0} - {1}", method.getName(), Arrays.toString(args));
    143143        }
    144144        switch (method.getName()) {
     
    156156                                        Thread.sleep(25);
    157157                                    } catch (InterruptedException e) {
    158                                         Main.warn(e);
     158                                        Logging.warn(e);
    159159                                        Thread.currentThread().interrupt();
    160160                                    }
     
    165165                    }
    166166                } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
    167                     Main.warn("Failed to access open files event: " + ex);
     167                    Logging.warn("Failed to access open files event: " + ex);
    168168                }
    169169            }
     
    175175                    args[1].getClass().getDeclaredMethod(closed ? "performQuit" : "cancelQuit").invoke(args[1]);
    176176                } catch (IllegalAccessException e) {
    177                     Main.debug(e);
     177                    Logging.debug(e);
    178178                    // with Java 9, module java.desktop does not export com.apple.eawt, use new Desktop API instead
    179179                    Class.forName("java.awt.desktop.QuitResponse").getMethod(closed ? "performQuit" : "cancelQuit").invoke(args[1]);
     
    188188            break;
    189189        default:
    190             Main.warn("OSX unsupported method: "+method.getName());
     190            Logging.warn("OSX unsupported method: "+method.getName());
    191191        }
    192192        return null;
     
    399399              .append(')');
    400400        } catch (IOException e) {
    401             Main.error(e);
     401            Logging.error(e);
    402402        }
    403403        return sb.toString();
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r12411 r12620  
    9090                return;
    9191            } catch (IOException | URISyntaxException e) {
    92                 Main.warn(e);
     92                Logging.warn(e);
    9393            }
    9494        }
     
    125125        } catch (IOException e) {
    126126            // lsb_release is not available on all Linux systems, so don't log at warning level
    127             Main.debug(e);
     127            Logging.debug(e);
    128128            return false;
    129129        }
     
    164164            }
    165165        } catch (IOException e) {
    166             Main.warn(e);
     166            Logging.warn(e);
    167167        }
    168168        return null;
     
    241241                }
    242242            } catch (IOException e) {
    243                 Main.debug(e);
     243                Logging.debug(e);
    244244                // Non LSB-compliant Linux system. List of common fallback release files: http://linuxmafia.com/faq/Admin/release-files.html
    245245                for (LinuxReleaseInfo info : new LinuxReleaseInfo[]{
     
    343343                    } catch (IOException e) {
    344344                        // Ignore
    345                         Main.trace(e);
     345                        Logging.trace(e);
    346346                    }
    347347                }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java

    r12321 r12620  
    177177                }
    178178            } catch (NumberFormatException | ReflectiveOperationException e) {
    179                 Main.error(e);
     179                Logging.error(e);
    180180            }
    181181        }
     
    304304            sb.append(" (").append(getCurrentBuild()).append(')');
    305305        } catch (ReflectiveOperationException e) {
    306             Main.error(e);
     306            Logging.error(e);
    307307        }
    308308        return sb.toString();
     
    346346            insecurePubKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(INSECURE_PUBLIC_KEY));
    347347        } catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
    348             Main.error(e);
     348            Logging.error(e);
    349349            return;
    350350        }
     
    362362                } catch (InvalidKeyException | NoSuchProviderException | SignatureException e) {
    363363                    // If exception this is not a certificate related to JOSM, just trace it
    364                     Main.trace(alias + " --> " + e.getClass().getName());
    365                     Main.trace(e);
     364                    Logging.trace(alias + " --> " + e.getClass().getName());
     365                    Logging.trace(e);
    366366                }
    367367            }
     
    385385            JOptionPane.showMessageDialog(Main.parent, message.toString(), tr("Warning"), JOptionPane.WARNING_MESSAGE);
    386386            for (String alias : insecureCertificates) {
    387                 Main.warn(tr("Removing insecure certificate from {0} keystore: {1}", WINDOWS_ROOT, alias));
     387                Logging.warn(tr("Removing insecure certificate from {0} keystore: {1}", WINDOWS_ROOT, alias));
    388388                try {
    389389                    ks.deleteEntry(alias);
    390390                } catch (KeyStoreException e) {
    391                     Main.error(e, tr("Unable to remove insecure certificate from keystore: {0}", e.getMessage()));
     391                    Logging.log(Logging.LEVEL_ERROR, tr("Unable to remove insecure certificate from keystore: {0}", e.getMessage()), e);
    392392                }
    393393            }
     
    404404            if (alias != null) {
    405405                // JOSM certificate found, return
    406                 Main.debug(tr("JOSM localhost certificate found in {0} keystore: {1}", WINDOWS_ROOT, alias));
     406                Logging.debug(tr("JOSM localhost certificate found in {0} keystore: {1}", WINDOWS_ROOT, alias));
    407407                return false;
    408408            }
    409409        } catch (ArrayIndexOutOfBoundsException e) {
    410410            // catch error of JDK-8172244 as bug seems to not be fixed anytime soon
    411             Main.error(e, "JDK-8172244 occured. Abort HTTPS setup");
     411            Logging.log(Logging.LEVEL_ERROR, "JDK-8172244 occured. Abort HTTPS setup", e);
    412412            return false;
    413413        }
     
    425425        }
    426426        // install it to Windows-ROOT keystore, used by IE, Chrome and Safari, but not by Firefox
    427         Main.info(tr("Adding JOSM localhost certificate to {0} keystore", WINDOWS_ROOT));
     427        Logging.info(tr("Adding JOSM localhost certificate to {0} keystore", WINDOWS_ROOT));
    428428        ks.setEntry(entryAlias, trustedCert, null);
    429429        return true;
     
    508508        Path templateFile = FileSystems.getDefault().getPath(javaLibPath, templateFileName);
    509509        if (!Files.isReadable(templateFile)) {
    510             Main.warn("extended font config - unable to find font config template file {0}", templateFile.toString());
     510            Logging.warn("extended font config - unable to find font config template file {0}", templateFile.toString());
    511511            return;
    512512        }
     
    532532                            extras.add(entry);
    533533                        } else {
    534                             Main.trace("extended font config - already registered font for charset ''{0}'' - skipping ''{1}''",
     534                            Logging.trace("extended font config - already registered font for charset ''{0}'' - skipping ''{1}''",
    535535                                    entry.charset, entry.name);
    536536                        }
    537537                    } else {
    538                         Main.trace("extended font config - Font ''{0}'' not found on system - skipping", entry.name);
     538                        Logging.trace("extended font config - Font ''{0}'' not found on system - skipping", entry.name);
    539539                    }
    540540                }
     
    548548                    String prevValue = props.getProperty(key);
    549549                    if (prevValue != null && !prevValue.equals(value)) {
    550                         Main.warn("extended font config - overriding ''{0}={1}'' with ''{2}''", key, prevValue, value);
     550                        Logging.warn("extended font config - overriding ''{0}={1}'' with ''{2}''", key, prevValue, value);
    551551                    }
    552552                    w.append(key + '=' + value + '\n');
     
    561561                    String prevValue = props.getProperty(key);
    562562                    if (prevValue != null && !prevValue.equals(value)) {
    563                         Main.warn("extended font config - overriding ''{0}={1}'' with ''{2}''", key, prevValue, value);
     563                        Logging.warn("extended font config - overriding ''{0}={1}'' with ''{2}''", key, prevValue, value);
    564564                    }
    565565                    w.append(key + '=' + value + '\n');
     
    575575            Utils.updateSystemProperty("sun.awt.fontconfig", fontconfigFile.toString());
    576576        } catch (IOException ex) {
    577             Main.error(ex);
     577            Logging.error(ex);
    578578        }
    579579    }
     
    603603            fontsAvail.add(""); // for devanagari
    604604        } catch (IOException ex) {
    605             Main.error(ex, false);
    606             Main.warn("extended font config - failed to load available Fonts");
     605            Logging.log(Logging.LEVEL_ERROR, ex);
     606            Logging.warn("extended font config - failed to load available Fonts");
    607607            fontsAvail = null;
    608608        }
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r11709 r12620  
    117117                }
    118118            } catch (UserCancelException ex) {
    119                 Main.warn(ex);
     119                Logging.warn(ex);
    120120            } catch (JosmRuntimeException ex) {
    121121                // Workaround to #10511 / #14185. To remove when #10511 is solved
    122                 Main.error(ex);
     122                Logging.error(ex);
    123123            }
    124124        }
    125125        if (optimizedWays.isEmpty()) {
    126126            // Problem: don't optimize
    127             Main.warn("Unable to join left-driving countries polygons");
     127            Logging.warn("Unable to join left-driving countries polygons");
    128128            optimizedWays.addAll(ways);
    129129        }
     
    142142            if (r.isMultipolygon() && LEFT.equals(r.get(DRIVING_SIDE)) &&
    143143                "inner".equals(r.getMembersFor(s).iterator().next().getRole())) {
    144                 if (Main.isDebugEnabled()) {
    145                     Main.debug("Skipping " + w.get("name:en") + " because inner part of " + r.get("name:en"));
     144                if (Logging.isDebugEnabled()) {
     145                    Logging.debug("Skipping {0} because inner part of {1}", w.get("name:en"), r.get("name:en"));
    146146                }
    147147                return;
     
    169169           return OsmReader.parseDataSet(is, null).getWays();
    170170        } catch (IllegalDataException | IOException ex) {
    171             Main.trace(ex);
     171            Logging.trace(ex);
    172172            return Collections.emptyList();
    173173        }
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r12520 r12620  
    286286        public boolean add(Shortcut shortcut) {
    287287            // expensive consistency check only in debug mode
    288             if (Main.isDebugEnabled()
     288            if (Logging.isDebugEnabled()
    289289                    && stream().map(Shortcut::getShortText).anyMatch(shortcut.getShortText()::equals)) {
    290                 Main.warn(new AssertionError(shortcut.getShortText() + " already added"));
     290                Logging.warn(new AssertionError(shortcut.getShortText() + " already added"));
    291291            }
    292292            return super.add(shortcut);
     
    430430        } else if (existing.isPresent()) {
    431431            // this always is a logic error in the hook
    432             Main.error("CONFLICT WITH SYSTEM KEY " + shortText + ": " + existing.get());
     432            Logging.error("CONFLICT WITH SYSTEM KEY " + shortText + ": " + existing.get());
    433433            return null;
    434434        }
     
    475475                int newmodifier = findNewOsxModifier(requestedGroup);
    476476                if (!findShortcut(requestedKey, newmodifier).isPresent()) {
    477                     Main.info("Reassigning OSX shortcut '" + shortText + "' from Meta to Ctrl because of conflict with " + conflict);
     477                    Logging.info("Reassigning OSX shortcut '" + shortText + "' from Meta to Ctrl because of conflict with " + conflict);
    478478                    return reassignShortcut(shortText, longText, requestedKey, conflict, requestedGroup, requestedKey, newmodifier);
    479479                }
     
    483483                    int newmodifier = getGroupModifier(m);
    484484                    if (!findShortcut(k, newmodifier).isPresent()) {
    485                         Main.info("Reassigning shortcut '" + shortText + "' from " + modifier + " to " + newmodifier +
     485                        Logging.info("Reassigning shortcut '" + shortText + "' from " + modifier + " to " + newmodifier +
    486486                                " because of conflict with " + conflict);
    487487                        return reassignShortcut(shortText, longText, requestedKey, conflict, m, k, newmodifier);
     
    512512            int m, int k, int newmodifier) {
    513513        Shortcut newsc = new Shortcut(shortText, longText, requestedKey, m, k, newmodifier, false, false);
    514         Main.info(tr("Silent shortcut conflict: ''{0}'' moved by ''{1}'' to ''{2}''.",
     514        Logging.info(tr("Silent shortcut conflict: ''{0}'' moved by ''{1}'' to ''{2}''.",
    515515            shortText, conflict.getShortText(), newsc.getKeyText()));
    516516        newsc.saveDefault();
  • trunk/src/org/openstreetmap/josm/tools/Territories.java

    r12484 r12620  
    6262        GeoPropertyIndex<Boolean> gpi = iso3166Cache.get(code);
    6363        if (gpi == null) {
    64             Main.warn(tr("Unknown territory id: {0}", code));
     64            Logging.warn(tr("Unknown territory id: {0}", code));
    6565            return false;
    6666        }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r12618 r12620  
    405405        CheckParameterUtil.ensureParameterNotNull(out, "out");
    406406        if (!out.exists() && !out.mkdirs()) {
    407             Main.warn("Unable to create directory "+out.getPath());
     407            Logging.warn("Unable to create directory "+out.getPath());
    408408        }
    409409        File[] files = in.listFiles();
     
    477477        boolean result = file.delete();
    478478        if (!result) {
    479             Main.warn(tr(warnMsg, file.getPath()));
     479            Logging.warn(tr(warnMsg, file.getPath()));
    480480        }
    481481        return result;
     
    503503        boolean result = dir.mkdirs();
    504504        if (!result) {
    505             Main.warn(tr(warnMsg, dir.getPath()));
     505            Logging.warn(tr(warnMsg, dir.getPath()));
    506506        }
    507507        return result;
     
    518518            c.close();
    519519        } catch (IOException e) {
    520             Main.warn(e);
     520            Logging.warn(e);
    521521        }
    522522    }
     
    542542                return f.toURI().toURL();
    543543            } catch (MalformedURLException ex) {
    544                 Main.error("Unable to convert filename " + f.getAbsolutePath() + " to URL");
     544                Logging.error("Unable to convert filename " + f.getAbsolutePath() + " to URL");
    545545            }
    546546        }
     
    763763        // Positions the stream at the beginning of first entry
    764764        ZipEntry ze = zis.getNextEntry();
    765         if (ze != null && Main.isDebugEnabled()) {
    766             Main.debug("Zip entry: "+ze.getName());
     765        if (ze != null && Logging.isDebugEnabled()) {
     766            Logging.debug("Zip entry: {0}", ze.getName());
    767767        }
    768768        return zis;
     
    878878     */
    879879    public static String execOutput(List<String> command) throws IOException {
    880         if (Main.isDebugEnabled()) {
    881             Main.debug(join(" ", command));
     880        if (Logging.isDebugEnabled()) {
     881            Logging.debug(join(" ", command));
    882882        }
    883883        Process p = new ProcessBuilder(command).start();
     
    909909        File josmTmpDir = new File(tmpDir, "JOSM");
    910910        if (!josmTmpDir.exists() && !josmTmpDir.mkdirs()) {
    911             Main.warn("Unable to create temp directory " + josmTmpDir);
     911            Logging.warn("Unable to create temp directory " + josmTmpDir);
    912912        }
    913913        return josmTmpDir;
     
    12161216                return true;
    12171217            } catch (MalformedURLException e) {
    1218                 Main.trace(e);
     1218                Logging.trace(e);
    12191219            }
    12201220        }
     
    12791279        if (value != null) {
    12801280            String old = System.setProperty(key, value);
    1281             if (Main.isDebugEnabled() && !value.equals(old)) {
     1281            if (Logging.isDebugEnabled() && !value.equals(old)) {
    12821282                if (!key.toLowerCase(Locale.ENGLISH).contains("password")) {
    1283                     Main.debug("System property '" + key + "' set to '" + value + "'. Old value was '" + old + '\'');
     1283                    Logging.debug("System property '" + key + "' set to '" + value + "'. Old value was '" + old + '\'');
    12841284                } else {
    1285                     Main.debug("System property '" + key + "' changed.");
     1285                    Logging.debug("System property '" + key + "' changed.");
    12861286                }
    12871287            }
     
    13181318    public static Document parseSafeDOM(InputStream is) throws ParserConfigurationException, IOException, SAXException {
    13191319        long start = System.currentTimeMillis();
    1320         if (Main.isDebugEnabled()) {
    1321             Main.debug("Starting DOM parsing of " + is);
    1322         }
     1320        Logging.debug("Starting DOM parsing of {0}", is);
    13231321        Document result = newSafeDOMBuilder().parse(is);
    1324         if (Main.isDebugEnabled()) {
    1325             Main.debug("DOM parsing done in " + getDurationString(System.currentTimeMillis() - start));
     1322        if (Logging.isDebugEnabled()) {
     1323            Logging.debug("DOM parsing done in {0}", getDurationString(System.currentTimeMillis() - start));
    13261324        }
    13271325        return result;
     
    13551353    public static void parseSafeSAX(InputSource is, DefaultHandler dh) throws ParserConfigurationException, SAXException, IOException {
    13561354        long start = System.currentTimeMillis();
    1357         if (Main.isDebugEnabled()) {
    1358             Main.debug("Starting SAX parsing of " + is + " using " + dh);
    1359         }
     1355        Logging.debug("Starting SAX parsing of {0} using {1}", is, dh);
    13601356        newSafeSAXParser().parse(is, dh);
    1361         if (Main.isDebugEnabled()) {
    1362             Main.debug("SAX parsing done in " + getDurationString(System.currentTimeMillis() - start));
     1357        if (Logging.isDebugEnabled()) {
     1358            Logging.debug("SAX parsing done in {0}", getDurationString(System.currentTimeMillis() - start));
    13631359        }
    13641360    }
     
    16651661            } catch (NoSuchFieldException e) {
    16661662                // Field is gone with Java 9, there's a method instead
    1667                 Main.trace(e);
     1663                Logging.trace(e);
    16681664                value = c.getDeclaredMethod("getProperty", String.class).invoke(null, "JRE_EXPIRATION_DATE");
    16691665            }
     
    16721668            }
    16731669        } catch (IllegalArgumentException | ReflectiveOperationException | SecurityException | ParseException e) {
    1674             Main.debug(e);
     1670            Logging.debug(e);
    16751671        }
    16761672        return null;
     
    16881684                    .connect().fetchContent().split("\n")[0];
    16891685        } catch (IOException e) {
    1690             Main.error(e);
     1686            Logging.error(e);
    16911687        }
    16921688        return null;
  • trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java

    r12382 r12620  
    8989            initFromPreferences(preferenceKey);
    9090        } catch (WindowGeometryException e) {
    91             Main.debug(e);
     91            Logging.debug(e);
    9292            initFromWindowGeometry(defaultGeometry);
    9393        }
     
    248248                return new WindowGeometry(new Point(x, y), new Dimension(w, h));
    249249            } else {
    250                 Main.warn(tr("Ignoring malformed geometry: {0}", arg));
     250                Logging.warn(tr("Ignoring malformed geometry: {0}", arg));
    251251            }
    252252        }
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r12382 r12620  
    160160                }
    161161            } catch (ReflectiveOperationException | IllegalArgumentException e) {
    162                 Main.error(e); // SAXException does not dump inner exceptions.
     162                Logging.error(e); // SAXException does not dump inner exceptions.
    163163                throwException(e);
    164164            }
     
    206206                    return f;
    207207                } catch (NoSuchFieldException ex) {
    208                     Main.trace(ex);
     208                    Logging.trace(ex);
    209209                    fields.put(s, null);
    210210                    return null;
     
    254254            } catch (SAXException e) {
    255255                // Exception very unlikely to happen, so no need to translate this
    256                 Main.error(e, "Cannot disable 'load-external-dtd' feature:");
     256                Logging.log(Logging.LEVEL_ERROR, "Cannot disable 'load-external-dtd' feature:", e);
    257257            }
    258258            reader.parse(new InputSource(in));
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportQueue.java

    r11535 r12620  
    5656        Logging.logWithStackTrace(Logging.LEVEL_ERROR, "Handled by bug report queue", report.getCause());
    5757        if (suppressAllMessages || suppressFor.stream().anyMatch(report::isSame)) {
    58             Main.info("User requested to skip error " + report);
     58            Logging.info("User requested to skip error " + report);
    5959        } else if (reportsToDisplay.size() > 100 || reportsToDisplay.stream().filter(report::isSame).count() >= 10) {
    60             Main.warn("Too many errors. Dropping " + report);
     60            Logging.warn("Too many errors. Dropping " + report);
    6161        } else {
    6262            reportsToDisplay.add(report);
     
    109109    private SuppressionMode displayFor(ReportedException e) {
    110110        if (handlers.stream().anyMatch(p -> p.test(e))) {
    111             Main.trace("Intercepted by handler.");
     111            Logging.trace("Intercepted by handler.");
    112112            return SuppressionMode.NONE;
    113113        }
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportSender.java

    r10618 r12620  
    2828import org.openstreetmap.josm.tools.HttpClient;
    2929import org.openstreetmap.josm.tools.HttpClient.Response;
     30import org.openstreetmap.josm.tools.Logging;
    3031import org.openstreetmap.josm.tools.OpenBrowser;
    3132import org.openstreetmap.josm.tools.Utils;
     
    6465            String openBrowserError = OpenBrowser.displayUrl(getJOSMTicketURL() + "?pdata_stored=" + debugTextPasteId);
    6566            if (openBrowserError != null) {
    66                 Main.warn(openBrowserError);
     67                Logging.warn(openBrowserError);
    6768                failed(openBrowserError);
    6869            }
    6970        } catch (BugReportSenderException e) {
    70             Main.warn(e);
     71            Logging.warn(e);
    7172            failed(e.getMessage());
    7273        }
  • trunk/src/org/openstreetmap/josm/tools/bugreport/JosmUpdatePanel.java

    r11196 r12620  
    1717import org.openstreetmap.josm.tools.GBC;
    1818import org.openstreetmap.josm.tools.ImageProvider;
     19import org.openstreetmap.josm.tools.Logging;
    1920import org.openstreetmap.josm.tools.WikiReader;
    2021
     
    6364            return Integer.parseInt(testedString.trim());
    6465        } catch (NumberFormatException | IOException e) {
    65             Main.warn(e, "Unable to detect latest version of JOSM:");
     66            Logging.log(Logging.LEVEL_WARN, "Unable to detect latest version of JOSM:", e);
    6667            return -1;
    6768        }
     
    9899            Main.platform.openUrl(Main.getJOSMWebsite());
    99100        } catch (IOException ex) {
    100             Main.warn(ex, "Unable to access JOSM website:");
     101            Logging.log(Logging.LEVEL_WARN, "Unable to access JOSM website:", ex);
    101102        }
    102103    }
  • trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java

    r11746 r12620  
    1919import java.util.function.Supplier;
    2020
    21 import org.openstreetmap.josm.Main;
     21import org.openstreetmap.josm.tools.Logging;
    2222import org.openstreetmap.josm.tools.StreamUtils;
    2323
     
    219219            }
    220220        } catch (RuntimeException t) { // NOPMD
    221             Main.warn(t);
     221            Logging.warn(t);
    222222            string = "<Error calling toString()>";
    223223        }
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r12589 r12620  
    1818import javax.xml.datatype.DatatypeFactory;
    1919
    20 import org.openstreetmap.josm.Main;
    2120import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2221import org.openstreetmap.josm.tools.CheckParameterUtil;
     22import org.openstreetmap.josm.tools.Logging;
    2323import org.openstreetmap.josm.tools.UncheckedParseException;
    2424
     
    5151            fact = DatatypeFactory.newInstance();
    5252        } catch (DatatypeConfigurationException e) {
    53             Main.error(e);
     53            Logging.error(e);
    5454        }
    5555        XML_DATE = fact;
Note: See TracChangeset for help on using the changeset viewer.