LogRecord getSourceClassName - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for LogRecord getSourceClassName method.

This code example shows how to use the following methods:getLevel, getMessage, getMillis, getSourceClassName, getThrown
 
public class LoggerShortFormat extends java.util.logging.Formatter {
  @Override 
  @Nonnull 
  public String format(@Nonnull final LogRecord record) {
    return record.getMillis() + " " +
        record.getLevel() + " [" +
        record.getSourceClassName() + "] " +
        record.getMessage() +
        (record.getThrown() != null ? " Stack trace:\n" + getStackTrace(record.getThrown()) : "") + "\n";
  } 
 
  public static void intialize() throws Exception { 
    InputStream input = null;
    try { 
      input = LoggerShortFormat.class.getClassLoader().getResourceAsStream("logging.properties");
      LogManager.getLogManager().readConfiguration(input);
    } finally { 
      if (input != null) {
        input.close();
8
CodeRank
This code example shows how to use the following methods:getLevel, getMillis, getSourceClassName, getSourceMethodName
    // Create a StringBuffer to contain the formatted record 
    // start with the date. 
    StringBuffer sb = new StringBuffer();
 
    // Get the date from the LogRecord and add it to the buffer 
    Date date = new Date(record.getMillis());
    sb.append(datef.format(date));
    sb.append(" ");
 
    // Get the level name and add it to the buffer 
    sb.append(record.getLevel().getName());
    sb.append(" ");
 
    String[] pieces = record.getSourceClassName().split("\\.");
    String name = pieces[pieces.length - 1];
    sb.append(name);
    sb.append(".");
    sb.append(record.getSourceMethodName());
    sb.append("  ");
 

7
CodeRank
This code example shows how to use the following methods:getLevel, getMillis, getSourceClassName, getSourceMethodName, getThreadID
This code example shows how to use the following methods:getLevel, getLoggerName, getMessage, getResourceBundle, getSequenceNumber
        check(logger.isLoggable(Level.WARNING));
        logger.addHandler(new Handler() {
            public void close() {} 
            public void flush() {} 
            public void publish(LogRecord l) {
                equal(l.getLoggerName(), name);
                equal(l.getMessage(), message);
                equal(l.getResourceBundle(), null);
                equal(l.getSourceClassName(), "LoggerSubclass");
                equal(l.getSourceMethodName(), "test");
                equal(l.getThrown(), null);
                equal(l.getLevel(), Level.WARNING);
 
                if (lastSequenceNumber.get() != -1) {
                    equal(lastSequenceNumber.get() + 1,
                          l.getSequenceNumber());
                    equal(lastThreadID.get(),
                          l.getThreadID());
                    equal((int) Thread.currentThread().getId(),
                          l.getThreadID());

7
CodeRank
This code example shows how to use the following methods:getLevel, getMillis, getSequenceNumber, getSourceClassName, getSourceMethodName
		StringBuffer buf = new StringBuffer(1000);
		// Bold any levels >= WARNING 
		buf.append("<tr>");
		buf.append("<td>");
 
		if (rec.getLevel().intValue() >= Level.WARNING.intValue())
		{ 
			buf.append("<b>");
			buf.append(rec.getLevel().getName());
			buf.append("</b>");
		} else 
		{ 
			buf.append(rec.getLevel().getName());
		} 
		buf.append("</td>");
		buf.append("<td>");
		buf.append(calcDate(rec.getMillis()));
		buf.append("</td>");
		buf.append("<td>");
		buf.append(formatMessage(rec));

7
CodeRank
This code example shows how to use the following methods:getLevel, getMessage, getMillis, getSequenceNumber, getSourceClassName
	 * @see java.util.logging.Handler#publish(java.util.logging.LogRecord) 
	 */ 
	@Override 
	public void publish(LogRecord record) {
		TestLogs testLogs = new TestLogs();		
		testLogs.setLogLevel(record.getLevel().getName());
		testLogs.setLogTime(new Date(record.getMillis()));
		testLogs.setMessage(record.getMessage());
		testLogs.setSequenceNumber(record.getSequenceNumber());
		testLogs.setClassName(record.getSourceClassName());
		testLogs.setMethodName(record.getSourceMethodName());
		testLogs.setThrowable(ClientCommon.toString(record.getThrown()));
		try { 
			remoteApi.insertLogMessage(testLogs);
		} catch (Exception ex) {
			LogHandler.teardown(); 
			System.out.println("error writing log to report engine; removing appender;");
			ex.printStackTrace();
		} 
	} 
6
CodeRank
This code example shows how to use the following methods:getMessage, getMillis, getSourceClassName, getSourceMethodName, getThreadID
This code example shows how to use the following methods:getLevel, getMessage, getSourceClassName, getSourceMethodName
import java.util.logging.LogRecord; 
 
public class ShortFormatter extends Formatter {
  // inefficient implementation 
  public String format(LogRecord record) {
    return record.getLevel() + " [" + record.getSourceClassName() + ":"
        + record.getSourceMethodName() + "] " + record.getMessage() + "\n";
  } 
} 
6
CodeRank
This code example shows how to use the following methods:getLevel, getMillis, getSourceClassName, getSourceMethodName, getThreadID
 
    if (threadFormat == null)
      threadFormat = new DecimalFormat(THREAD_PATTERN);
 
    StringBuilder sb = new StringBuilder(180)
        .append(dateFormat.format(new Date(record.getMillis())))
        .append(threadFormat.format(record.getThreadID()))
        .append(" ");
    String s = record.getSourceClassName();
    if (s == null)
      sb.append(SPACES_32);
    else 
      { 
        s = s.trim();
        int i = s.lastIndexOf(".");
        if (i != - 1)
          s = s.substring(i + 1);
 
        s = (s + SPACES_32).substring(0, 32);
      } 

6
CodeRank
This code example shows how to use the following methods:getLevel, getMessage, getMillis, getSourceClassName, getThrown
import java.util.logging.Logger; 
 
public class LoggerShortFormat extends java.util.logging.Formatter {
  // inefficient implementation 
  public String format(LogRecord record) {
    Throwable throwable = record.getThrown();
    if (throwable != null) {
      throwable.printStackTrace();
    } 
     return 
       record.getMillis() + " " +  
       record.getLevel() + " [" +
       record.getSourceClassName() + "] " +
       record.getMessage() + "\n";
  } 
   
  public static void initialize() { 
    Logger root = Logger.getLogger("");
    Handler[] handlers = root.getHandlers();  // returns 1
 
6
CodeRank
getSourceClassName Method Overview
Get the name of the class that (allegedly) issued the logging request.
See Code Examples for other Java 8 LogRecord Methods: