private String formatString(
        MLevel l, String srcClass, String srcMeth, String msg, Object[] params, Throwable t) {
      boolean add_parens = (srcMeth != null && !srcMeth.endsWith(")"));

      StringBuffer sb = new StringBuffer(256);
      sb.append(l.getLineHeader());
      sb.append(' ');
      if (srcClass != null && srcMeth != null) {
        sb.append('[');
        sb.append(srcClass);
        sb.append('.');
        sb.append(srcMeth);
        if (add_parens) sb.append("()");
        sb.append(']');
      } else if (srcClass != null) {
        sb.append('[');
        sb.append(srcClass);
        sb.append(']');
      } else if (srcMeth != null) {
        sb.append('[');
        sb.append(srcMeth);
        if (add_parens) sb.append("()");
        sb.append(']');
      }
      if (msg == null) {
        if (params != null) {
          sb.append("params: ");
          for (int i = 0, len = params.length; i < len; ++i) {
            if (i != 0) sb.append(", ");
            sb.append(params[i]);
          }
        }
      } else {
        if (params == null) sb.append(msg);
        else {
          MessageFormat mfmt = new MessageFormat(msg);
          sb.append(mfmt.format(params));
        }
      }

      if (t != null) {
        sb.append(SEP);
        sb.append(ThrowableUtils.extractStackTrace(t));
      }

      return sb.toString();
    }
Beispiel #2
0
 /**
  * getLocalizedMessage is used to localize the messages being used in exceptions with arguments
  * inserted appropriately.
  */
 public static String getLocalizedMessage(Logger logger, String key, Object[] args) {
   try {
     ResourceBundle rb = logger.getResourceBundle();
     String message = rb.getString(key);
     return MessageFormat.format(message, args);
   } catch (Exception ex) {
     logger.log(Level.FINE, "JTS:Error while localizing the log message");
     return key;
   }
 }