getSourceClassName ( )源码实例Demo

java.util.logging.LogRecord#getSourceClassName ( )源码实例Demo

下面列出了java.util.logging.LogRecord#getSourceClassName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: RipplePower   文件: BriefLogFormatter.java
@Override
public String format(LogRecord logRecord) {
	Object[] arguments = new Object[6];
	arguments[0] = logRecord.getLevel().getName();
	String fullClassName = logRecord.getSourceClassName();
	int lastDot = fullClassName.lastIndexOf('.');
	String className = fullClassName.substring(lastDot + 1);
	arguments[1] = className;
	arguments[2] = logRecord.getSourceMethodName();
	arguments[3] = new Date(logRecord.getMillis());
	arguments[4] = logRecord.getMessage();
	if (logRecord.getThrown() != null) {
		Writer result = new StringWriter();
		logRecord.getThrown().printStackTrace(new PrintWriter(result));
		arguments[5] = result.toString();
	} else {
		arguments[5] = "";
	}

	return messageFormat.format(arguments);
}
 
源代码2 项目: appengine-java-vm-runtime   文件: JsonFormatter.java
@Override
public synchronized String formatMessage(LogRecord record) {
    StringBuilder sb = new StringBuilder();
    if (record.getSourceClassName() != null) {
        sb.append(record.getSourceClassName());
    } else {
        sb.append(record.getLoggerName());
    }
    if (record.getSourceMethodName() != null) {
        sb.append(' ');
        sb.append(record.getSourceMethodName());
    }
    sb.append(": ");
    sb.append(super.formatMessage(record));
    Throwable thrown = record.getThrown();
    if (thrown != null) {
        StringWriter sw = new StringWriter();
        try (PrintWriter pw = new PrintWriter(sw);) {
            sb.append("\n");
            thrown.printStackTrace(pw);
        }
        sb.append(sw.getBuffer());
    }
    return sb.toString();
}
 
源代码3 项目: rapidminer-studio   文件: LeanFormatter.java
@Override
public String format(LogRecord record) {
	StringBuilder b = new StringBuilder();
	b.append(dateFormat.format(new Date(record.getMillis())));
	b.append(" ");
	b.append(record.getLevel().getLocalizedName());
	b.append(": ");
	b.append(formatMessage(record));
	String className = record.getSourceClassName();
	if (className != null) {
		int dot = className.lastIndexOf('.');
		if (dot != -1) {
			className = className.substring(dot + 1);
		}
		b.append(" (").append(className).append(".").append(record.getSourceMethodName()).append("())");
	}
	b.append("\n");
	append(record.getThrown(), b);
	return b.toString();
}
 
源代码4 项目: kumuluzee   文件: JavaUtilFormatter.java
@Override
public String format(LogRecord record) {

    ZonedDateTime zonedDateTime = Instant.ofEpochMilli(record.getMillis()).atZone(ZoneId.systemDefault());

    String source = record.getSourceClassName() != null ? record.getSourceClassName() : record.getLoggerName();
    String message = formatMessage(record);
    String throwable = "";

    if (record.getThrown() != null) {

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        pw.println();
        record.getThrown().printStackTrace(pw);
        pw.close();
        throwable = sw.toString();
    }

    return zonedDateTime.format(timestampFormat) + " " +
            record.getLevel().getName() + " -- " +
            source + " -- " +
            message + throwable + "\n";
}
 
源代码5 项目: baratine   文件: PatternFormatter.java
@Override
public void formatImpl(StringBuilder sb, LogRecord log)
{
  String name = log.getSourceClassName();
  
  sb.append(_filter.format(name));
}
 
源代码6 项目: Kylin   文件: MyLogFormatter.java
/**
 * Format the given LogRecord.
 * 
 * @param record
 *            the log record to be formatted.
 * @return a formatted log record
 */
public synchronized String format(LogRecord record) {
    StringBuffer sb = new StringBuffer();
    // Minimize memory allocations here.
    Timestamp ts = new Timestamp(record.getMillis());
    String text = ts.toString();
    sb.append("JUL ");
    sb.append(text);
    sb.append(" ");
    if (record.getSourceClassName() != null) {
        sb.append(record.getSourceClassName());
    } else {
        sb.append(record.getLoggerName());
    }
    if (record.getSourceMethodName() != null) {
        sb.append(" ");
        sb.append(record.getSourceMethodName());
    }
    sb.append(lineSeparator);
    String message = formatMessage(record);
    sb.append(record.getLevel().getLocalizedName());
    sb.append(": ");
    sb.append(message);
    sb.append(lineSeparator);
    if (record.getThrown() != null) {
        try {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            record.getThrown().printStackTrace(pw);
            pw.close();
            sb.append(sw.toString());
        } catch (Exception ex) {
        }
    }
    return sb.toString();
}
 
源代码7 项目: openjdk-jdk9   文件: TestLogHandler.java
@Override
public void publish(LogRecord record) {
    String msg = record.getMessage();
    String method = record.getSourceMethodName();
    String className = record.getSourceClassName();
    if (msg.contains(illegal)) {
        testFailed = true;
    }
    if (msg.contains("attribute names=")) {
        System.err.println("LOG: " + className + "." + method + ": " + msg);
    }
}
 
源代码8 项目: alcor   文件: LogFormatter.java
@Override
public String format(LogRecord lr) {
    String strSourceClassName = lr.getSourceClassName();
    if (strSourceClassName == null)
        strSourceClassName = " ";
    return String.format("[%1$tF %1$tT] [%2$-7s] %4$s %6$s %7$s%n",
            new Date(lr.getMillis()),
            lr.getLevel(),
            (lr.getLoggerName() == null) ? " " : lr.getLoggerName(),
            (strSourceClassName == null) ? " " : strSourceClassName.substring(strSourceClassName.lastIndexOf(".") + 1),
            (lr.getSourceMethodName() == null) ? " " : lr.getSourceMethodName(),
            lr.getMessage(),
            (lr.getThrown() == null) ? " " : lr.getThrown().getMessage()
    );
}
 
源代码9 项目: journaldev   文件: MyFormatter.java
@Override
public String format(LogRecord record) {
    return record.getThreadID()+"::"+record.getSourceClassName()+"::"
            +record.getSourceMethodName()+"::"
            +new Date(record.getMillis())+"::"
            +record.getMessage()+"\n";
}
 
源代码10 项目: snowflake-jdbc   文件: SFFormatter.java
@Override
public String format(LogRecord record)
{
  int lineNumber = -1;
  String className = record.getSourceClassName();
  final String methodName = record.getSourceMethodName();
  StackTraceElement[] stackTraces = Thread.currentThread().getStackTrace();
  for (StackTraceElement ste : stackTraces)
  {
    if (className.equals(ste.getClassName())
        && methodName.equals(ste.getMethodName()))
    {
      lineNumber = ste.getLineNumber();
      break;
    }
  }
  if (className.startsWith(CLASS_NAME_PREFIX))
  {
    className = "n.s.c" + className.substring(CLASS_NAME_PREFIX.length());
  }
  else if (className.startsWith(INFORMATICA_V1_CLASS_NAME_PREFIX))
  {
    className = "c.s" + className.substring(
        INFORMATICA_V1_CLASS_NAME_PREFIX.length());
  }

  StringBuilder builder = new StringBuilder(1000);
  builder.append(df.format(new Date(record.getMillis()))).append(" ");
  builder.append(className).append(" ");
  builder.append(record.getLevel()).append(" ");
  builder.append(methodName).append(":");
  builder.append(lineNumber).append(" - ");
  builder.append(formatMessage(record));
  builder.append("\n");
  return builder.toString();
}
 
/**
 * Format the given LogRecord.
 * @param record the log record to be formatted.
 * @return a formatted log record
 */
@Override
public synchronized String format(LogRecord record) {
  StringBuffer sb = new StringBuffer();
  if (record.getSourceClassName() != null) {
    sb.append(record.getSourceClassName());
  } else {
    sb.append(record.getLoggerName());
  }
  if (record.getSourceMethodName() != null) {
    sb.append(" ");
    sb.append(record.getSourceMethodName());
  }
  sb.append(": ");
  String message = formatMessage(record);
  sb.append(message);
  sb.append("\n");
  if (record.getThrown() != null) {
    try {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      record.getThrown().printStackTrace(pw);
      pw.close();
      sb.append(sw.toString());
    } catch (Exception ex) {
    }
  }
  return sb.toString();
}
 
源代码12 项目: openjdk-jdk8u   文件: TestLogHandler.java
@Override
public void publish(LogRecord record) {
    String msg = record.getMessage();
    String method = record.getSourceMethodName();
    String className = record.getSourceClassName();
    if (msg.contains(illegal)) {
        testFailed = true;
    }
    if (msg.contains("attribute names=")) {
        System.err.println("LOG: " + className + "." + method + ": " + msg);
    }
}
 
源代码13 项目: cplus-libparser   文件: LogFormatter.java
@Override
public String format(LogRecord record) {
  dat.setTime(record.getMillis());
  String source;
  if (record.getSourceClassName() != null) {
      source = record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf('.') + 1);
      if (record.getSourceMethodName() != null) {
         source += "." + record.getSourceMethodName();
      }
  } else {
      source = record.getLoggerName();
  }
  String message = formatMessage(record);
  String throwable = "";
  if (record.getThrown() != null) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      pw.println();
      record.getThrown().printStackTrace(pw);
      pw.close();
      throwable = sw.toString();
  }
  return String.format(format,
                       dat,
                       source,
                       record.getLoggerName(),
                       record.getLevel(),
                       message,
                       throwable);
}
 
源代码14 项目: jdk8u-jdk   文件: TestLogHandler.java
@Override
public void publish(LogRecord record) {
    String msg = record.getMessage();
    String method = record.getSourceMethodName();
    String className = record.getSourceClassName();
    if (msg.contains(illegal)) {
        testFailed = true;
    }
    if (msg.contains("attribute names=")) {
        System.err.println("LOG: " + className + "." + method + ": " + msg);
    }
}
 
源代码15 项目: twister2   文件: Twister2LogFormatter.java
@Override
public String format(LogRecord record) {
  dat.setTime(record.getMillis());
  String source;
  if (record.getSourceClassName() != null) {
    source = record.getSourceClassName();
    if (record.getSourceMethodName() != null) {
      source += " " + record.getSourceMethodName();
    }
  } else {
    source = record.getLoggerName();
  }
  String message = formatMessage(record);
  String throwable = "";
  if (record.getThrown() != null) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.println();
    record.getThrown().printStackTrace(pw);
    pw.close();
    throwable = sw.toString();
  }
  return String.format(FORMAT,
      dat,
      source,
      record.getLoggerName(),
      record.getLevel().getLocalizedName(),
      message,
      throwable,
      componentName,
      this.getThreadName(record.getThreadID())
  );
}
 
源代码16 项目: nomulus   文件: GcpJsonFormatter.java
@Override
public String format(LogRecord record) {
  // Add an extra newline before the message. Stackdriver does not show newlines correctly, and
  // treats them as whitespace. If you want to see correctly formatted log message, expand the
  // log and look for the jsonPayload.message field. This newline makes sure that the entire
  // message starts on its own line, so that indentation within the message is correct.

  String message = "\n" + record.getMessage();
  String severity = severityFor(record.getLevel());

  // The rest is mostly lifted from java.util.logging.SimpleFormatter.
  String stacktrace = "";
  if (record.getThrown() != null) {
    StringWriter sw = new StringWriter();
    try (PrintWriter pw = new PrintWriter(sw)) {
      pw.println();
      record.getThrown().printStackTrace(pw);
    }
    stacktrace = sw.toString();
  }

  String source;
  if (record.getSourceClassName() != null) {
    source = record.getSourceClassName();
    if (record.getSourceMethodName() != null) {
      source += " " + record.getSourceMethodName();
    }
  } else {
    source = record.getLoggerName();
  }

  return gson.toJson(
          ImmutableMap.of(SEVERITY, severity, SOURCE, source, MESSAGE, message + stacktrace))
      + '\n';
}
 
源代码17 项目: uima-uimaj   文件: UIMALogFormatter.java
public synchronized String format(LogRecord record) {
  // if record is null, return an empty String
  if (record == null) {
    return "";
  }

  StringBuffer buffer = new StringBuffer(100);

  // create timestamp
  Date timestamp = new Date(record.getMillis());
  String timestampStr = tsFormatter.format(timestamp);
  // append timestamp to the output string
  buffer.append(timestampStr);

  // append source thread ID
  buffer.append(" - ");
  buffer.append(record.getThreadID());

  // append source class if logrb() method was used, otherwise append logger name
  buffer.append(": ");
  if (record.getSourceClassName() == null || record.getSourceClassName().equals("")) {
    buffer.append(record.getLoggerName());
  } else {
    buffer.append(record.getSourceClassName());
  }

  // append source method if logrb() was used
  if (record.getSourceMethodName() != null) {
    buffer.append('.');
    buffer.append(record.getSourceMethodName());
  }

  // append message level
  buffer.append(": ");
  buffer.append(record.getLevel().getLocalizedName());

  // append message
  buffer.append(": ");
  buffer.append(record.getMessage());

  // append exception if avaialble
  if (record.getThrown() != null) {
    buffer.append(CRLF);
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter);
    record.getThrown().printStackTrace(printWriter);
    printWriter.close();
    buffer.append(stringWriter.toString());
  }

  // append new line at the end
  buffer.append(CRLF);

  // return log entry
  return buffer.toString();
}
 
源代码18 项目: netbeans   文件: LogFormatter.java
/**
 * Format the given message to XML.
 * @param record the log record to be formatted.
 * @return a formatted log record
 */
public @Override String format(LogRecord record) {
    StringBuffer sb = new StringBuffer(1000);
    sb.append("<record>\n");// NOI18N
    
    sb.append("  <date>");// NOI18N
    appendISO8601(sb, record.getMillis());
    sb.append("</date>\n");// NOI18N
    
    sb.append("  <millis>");// NOI18N
    sb.append(record.getMillis());
    sb.append("</millis>\n");// NOI18N
    
    sb.append("  <sequence>");// NOI18N
    sb.append(record.getSequenceNumber());
    sb.append("</sequence>\n");// NOI18N
    
    String name = record.getLoggerName();
    if (name != null) {
        sb.append("  <logger>");// NOI18N
        escape(sb, name);
        sb.append("</logger>\n");// NOI18N
    }
    
    sb.append("  <level>");// NOI18N
    String level = Integer.toString(record.getLevel().intValue());
    escape(sb, level);
    sb.append("</level>\n");// NOI18N
    
    if (record.getSourceClassName() != null) {
        sb.append("  <class>");// NOI18N
        escape(sb, record.getSourceClassName());
        sb.append("</class>\n");// NOI18N
    }
    
    if (record.getSourceMethodName() != null) {
        sb.append("  <method>");// NOI18N
        escape(sb, record.getSourceMethodName());
        sb.append("</method>\n");// NOI18N
    }
    
    sb.append("  <thread>");// NOI18N
    sb.append(record.getThreadID());
    sb.append("</thread>\n");// NOI18N
    
    String message = record.getMessage();
    if (message != null) {
        sb.append("  <message>");// NOI18N
        escape(sb, message);
        sb.append("</message>\n");// NOI18N
    }
            
    // If the message is being localized, output the key, resource
    // bundle name, and params.
    ResourceBundle bundle = record.getResourceBundle();
    try {
        if (bundle != null && bundle.getString(message) != null) {
            sb.append("  <key>");// NOI18N
            escape(sb, message);
            sb.append("</key>\n");// NOI18N
            sb.append("  <catalog>");// NOI18N
            escape(sb, record.getResourceBundleName());
            sb.append("</catalog>\n");// NOI18N
        }
    } catch (Exception exc) {
        // The message is not in the catalog.  Drop through.
        Logger.getLogger(LogFormatter.class.getName()).log(Level.FINE, "Catalog loading error", exc);// NOI18N
    }

    Object parameters[] = record.getParameters();
    //  Check to see if the parameter was not a messagetext format
    //  or was not null or empty
    if ( parameters != null && parameters.length != 0
            && (message == null || message.indexOf("{") == -1) ) {
        for (int i = 0; i < parameters.length; i++) {
            sb.append("  <param>");// NOI18N
            try {
                escape(sb, paramToString(parameters[i]));
            } catch (Exception ex) {
                sb.append("???");// NOI18N
            }
            sb.append("</param>\n");// NOI18N
        }
    }
    
    if (record.getThrown() != null) {
        printThrown(record.getThrown(), sb);
    }
    
    sb.append("</record>\n");// NOI18N
    return sb.toString();
}
 
源代码19 项目: netbeans   文件: Log.java
private Logger getPackageLogger() {
      if (logger == null) {
          String prop = System.getProperty(packageName, DEFAULT_NAME);
          for (int i = 1; i < LEVELS.length; i++) {
              if (prop.toLowerCase().equals(LEVEL_NAMES[i].toLowerCase())) {
                  level = LEVELS[i];
                  break;
              }
          }
          LogManager.getLogManager().addLogger(new Logger(packageName, null)
{});
          logger = LogManager.getLogManager().getLogger(packageName);
          if (logger == null) {
              System.out.println(packageName + ": "
		   + rb.getString("CANT_GET_LOGGER"));
              return Logger.getLogger("global");
          }
          try {
              logger.setLevel(level);
              Handler handler = new ConsoleHandler();
              handler.setLevel(level);
// Default handlers don't provide class name or method name, so roll our own
logger.setUseParentHandlers(false);
Formatter formatter = new Formatter() {
	public String format(LogRecord record) {
	    StringBuffer s = new StringBuffer();
	    s.append(record.getLevel().getLocalizedName());
	    s.append(' ');
	    if (record.getLoggerName() != null) {
		s.append('[');
		s.append(record.getLoggerName());
		s.append("]: ");
	    }
	    if (record.getSourceClassName() != null) {
		s.append("| ");
		if (record.getLevel().equals(Level.FINEST)) {
		    String className = record.getSourceClassName();
		    s.append(className.substring(Math.max(className.lastIndexOf('.')+1,0)));
		} else {
		    s.append(record.getSourceClassName());
		}
		s.append(' ');
	    }
	    if (record.getSourceMethodName() != null) {
		s.append("|  ");
		s.append(record.getSourceMethodName());
		s.append("( ");
		Object[] parms = record.getParameters();
		if (parms != null) {
		    for (int i = 0; i < parms.length; i++) {
			if (i != 0) {
			    s.append(", ");
			}
			s.append(parms[i]);
		    }
		}
		s.append(" ) ");
	    }
	    if (record.getThrown() != null) {
		s.append("| ");
		s.append(record.getThrown());
	    }
	    if (record.getMessage() != null) {
		s.append('|');
		s.append(record.getMessage());
	    }
	    s.append('\n');
	    return s.toString();
	}
                  };
              handler.setFormatter(formatter);
              logger.addHandler(handler);
          }
          catch (SecurityException e) {
          }
      }

      return logger;
  }
 
源代码20 项目: cxf   文件: LogUtilsTest.java
public void publish(LogRecord record) {
    cname = record.getSourceClassName();
    mname = record.getSourceMethodName();
}