Ignore:
Timestamp:
2013-09-23T16:47:50+02:00 (13 years ago)
Author:
Don-vip
Message:

Rework console output:

  • new log level "error"
  • Replace nearly all calls to system.out and system.err to Main.(error|warn|info|debug)
  • Remove some unnecessary debug output
  • Some messages are modified (removal of "Info", "Warning", "Error" from the message itself -> notable i18n impact but limited to console error messages not seen by the majority of users, so that's ok)
File:
1 edited

Legend:

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

    r6143 r6248  
    4141import javax.swing.KeyStroke;
    4242import javax.swing.UIManager;
     43import javax.swing.UnsupportedLookAndFeelException;
    4344
    4445import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
     
    199200
    200201    /**
    201      * Logging level (3 = debug, 2 = info, 1 = warn, 0 = none).
    202      */
    203     static public int log_level = 2;
    204     /**
    205      * Print a warning message if logging is on.
     202     * Logging level (4 = debug, 3 = info, 2 = warn, 1 = error, 0 = none).
     203     * @since 6248
     204     */
     205    public static int logLevel = 3;
     206   
     207    /**
     208     * Prints an error message if logging is on.
    206209     * @param msg The message to print.
    207      */
    208     static public void warn(String msg) {
    209         if (log_level < 1)
     210     * @since 6248
     211     */
     212    public static void error(String msg) {
     213        if (logLevel < 1)
     214            return;
     215        System.err.println(tr("ERROR: {0}", msg));
     216    }
     217   
     218    /**
     219     * Prints a warning message if logging is on.
     220     * @param msg The message to print.
     221     */
     222    public static void warn(String msg) {
     223        if (logLevel < 2)
    210224            return;
    211225        System.err.println(tr("WARNING: {0}", msg));
    212226    }
    213     /**
    214      * Print an informational message if logging is on.
     227   
     228    /**
     229     * Prints an informational message if logging is on.
    215230     * @param msg The message to print.
    216231     */
    217     static public void info(String msg) {
    218         if (log_level < 2)
     232    public static void info(String msg) {
     233        if (logLevel < 3)
    219234            return;
    220         System.err.println(tr("INFO: {0}", msg));
    221     }
    222     /**
    223      * Print an debug message if logging is on.
     235        System.out.println(tr("INFO: {0}", msg));
     236    }
     237   
     238    /**
     239     * Prints a debug message if logging is on.
    224240     * @param msg The message to print.
    225241     */
    226     static public void debug(String msg) {
    227         if (log_level < 3)
     242    public static void debug(String msg) {
     243        if (logLevel < 4)
    228244            return;
    229         System.err.println(tr("DEBUG: {0}", msg));
    230     }
    231     /**
    232      * Print a formated warning message if logging is on. Calls {@link MessageFormat#format}
     245        System.out.println(tr("DEBUG: {0}", msg));
     246    }
     247   
     248    /**
     249     * Prints a formated error message if logging is on. Calls {@link MessageFormat#format}
    233250     * function to format text.
    234251     * @param msg The formated message to print.
    235252     * @param objects The objects to insert into format string.
    236      */
    237     static public void warn(String msg, Object... objects) {
    238         warn(MessageFormat.format(msg, objects));
    239     }
    240     /**
    241      * Print a formated informational message if logging is on. Calls {@link MessageFormat#format}
     253     * @since 6248
     254     */
     255    public static void error(String msg, Object... objects) {
     256        error(MessageFormat.format(msg, objects));
     257    }
     258   
     259    /**
     260     * Prints a formated warning message if logging is on. Calls {@link MessageFormat#format}
    242261     * function to format text.
    243262     * @param msg The formated message to print.
    244263     * @param objects The objects to insert into format string.
    245264     */
    246     static public void info(String msg, Object... objects) {
    247         info(MessageFormat.format(msg, objects));
    248     }
    249     /**
    250      * Print a formated debug message if logging is on. Calls {@link MessageFormat#format}
     265    public static void warn(String msg, Object... objects) {
     266        warn(MessageFormat.format(msg, objects));
     267    }
     268   
     269    /**
     270     * Prints a formated informational message if logging is on. Calls {@link MessageFormat#format}
    251271     * function to format text.
    252272     * @param msg The formated message to print.
    253273     * @param objects The objects to insert into format string.
    254274     */
    255     static public void debug(String msg, Object... objects) {
     275    public static void info(String msg, Object... objects) {
     276        info(MessageFormat.format(msg, objects));
     277    }
     278   
     279    /**
     280     * Prints a formated debug message if logging is on. Calls {@link MessageFormat#format}
     281     * function to format text.
     282     * @param msg The formated message to print.
     283     * @param objects The objects to insert into format string.
     284     */
     285    public static void debug(String msg, Object... objects) {
    256286        debug(MessageFormat.format(msg, objects));
     287    }
     288   
     289    /**
     290     * Prints an error message for the given Throwable.
     291     * @param t The throwable object causing the error
     292     * @since 6248
     293     */
     294    public static void error(Throwable t) {
     295        error(t.getClass().getName()+": "+t.getMessage());
     296    }
     297   
     298    /**
     299     * Prints a warning message for the given Throwable.
     300     * @param t The throwable object causing the error
     301     * @since 6248
     302     */
     303    public static void warn(Throwable t) {
     304        warn(t.getClass().getName()+": "+t.getMessage());
    257305    }
    258306
     
    531579        Object existing = inputMap.get(keyStroke);
    532580        if (existing != null && !existing.equals(action)) {
    533             System.out.println(String.format("Keystroke %s is already assigned to %s, will be overridden by %s", keyStroke, existing, action));
     581            info(String.format("Keystroke %s is already assigned to %s, will be overridden by %s", keyStroke, existing, action));
    534582        }
    535583        inputMap.put(keyStroke, action);
     
    600648                UIManager.setLookAndFeel(laf);
    601649            }
    602             catch (final java.lang.ClassNotFoundException e) {
    603                 System.out.println("Look and Feel not found: " + laf);
     650            catch (final ClassNotFoundException e) {
     651                info("Look and Feel not found: " + laf);
    604652                Main.pref.put("laf", defaultlaf);
    605653            }
    606             catch (final javax.swing.UnsupportedLookAndFeelException e) {
    607                 System.out.println("Look and Feel not supported: " + laf);
     654            catch (final UnsupportedLookAndFeelException e) {
     655                info("Look and Feel not supported: " + laf);
    608656                Main.pref.put("laf", defaultlaf);
    609657            }
     
    853901        String os = System.getProperty("os.name");
    854902        if (os == null) {
    855             System.err.println("Your operating system has no name, so I'm guessing its some kind of *nix.");
     903            warn("Your operating system has no name, so I'm guessing its some kind of *nix.");
    856904            platform = new PlatformHookUnixoid();
    857905        } else if (os.toLowerCase().startsWith("windows")) {
     
    864912            platform = new PlatformHookOsx();
    865913        } else {
    866             System.err.println("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix.");
     914            warn("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix.");
    867915            platform = new PlatformHookUnixoid();
    868916        }
     
    948996            }
    949997        }
    950         System.err.println("Error: Could not recognize Java Version: "+version);
     998        error("Could not recognize Java Version: "+version);
    951999    }
    9521000
Note: See TracChangeset for help on using the changeset viewer.