當前位置: 首頁>>代碼示例>>Java>>正文


Java LogRecord.getSourceClassName方法代碼示例

本文整理匯總了Java中java.util.logging.LogRecord.getSourceClassName方法的典型用法代碼示例。如果您正苦於以下問題:Java LogRecord.getSourceClassName方法的具體用法?Java LogRecord.getSourceClassName怎麽用?Java LogRecord.getSourceClassName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.logging.LogRecord的用法示例。


在下文中一共展示了LogRecord.getSourceClassName方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@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();
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:21,代碼來源:LeanFormatter.java

示例2: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public synchronized String format(LogRecord record) {
	if (record == null) {
		return "Cannot log null logging records.";
	}
	try {
		if (record.getThrown() != null) {
			return record.getLevel() + ": " +
					LogFormatter.sdf.format(new Date()) + " - " +
					record.getSourceClassName() + ":" +
					record.getSourceMethodName() + " - " +
					formatMessage(record) + Line_Separator + getTrace(record.getThrown()) + Line_Separator;
		}
		return record.getLevel() + ": " +
				LogFormatter.sdf.format(new Date()) + " - " +
				record.getSourceClassName() + ":" +
				record.getSourceMethodName() + " - " +
				formatMessage(record) + Line_Separator;
	} catch (Exception e) {
		return "Failed to parse logging record.";
	}
}
 
開發者ID:howma03,項目名稱:sporticus,代碼行數:23,代碼來源:LogFormatter.java

示例3: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/**
     * Format the given LogRecord.
     * @param record the log record to be formatted.
     * @return a formatted log record
     */
    public synchronized String format(LogRecord record) {
        Date date=new Date();
        String time=dateFormat.format(date);
	StringBuffer sb = new StringBuffer(time);
	sb.append(record.getLevel().getLocalizedName());
	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(": ");
	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();
    }
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:38,代碼來源:AEConsoleFormatter.java

示例4: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public synchronized String format(LogRecord record) {

		final String sourceClassName = record.getSourceClassName();
		final String sourceMethodName = record.getSourceMethodName();

		mCalendar.setTimeInMillis(record.getMillis());

		final StringBuilder sb = new StringBuilder();
		sb.append(String.format("%1$tD %1$tT.%1$tL [%2$6s] ", mCalendar, record.getLevel().toString()));

		if (sourceClassName != null) {
			sb.append(sourceClassName);
		} else {
			String loggerName = record.getLoggerName();
			sb.append(loggerName);
		}
		sb.append(" ");

		if (sourceMethodName != null) {
			sb.append(String.format("#%s", sourceMethodName));
		}
		sb.append(" ");
		sb.append(formatMessage(record));
		sb.append("\n");
		Throwable thrown = record.getThrown();
		if (thrown != null) {
			sb.append(record.getThrown());
		}
		return sb.toString();
	}
 
開發者ID:riversun,項目名稱:java-firebase-fcm-client,代碼行數:31,代碼來源:LogFormatter.java

示例5: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public String format( LogRecord rec) {
	int ii;
	StringBuffer outbuf = new StringBuffer(200);
	long tmval = rec.getMillis();
	if (timeType == DleseLogManager.LOG_UTCTIME) {
		// convert local time to UTC
		TimeZone tz = TimeZone.getDefault();
		tmval -= tz.getRawOffset();
	}
	outbuf.append( dateformat.format( new Date(tmval)));
	outbuf.append(" ");
	outbuf.append(rec.getLevel());
	outbuf.append(" ");
	String classname = rec.getSourceClassName();
	int ix = classname.lastIndexOf(".");
	if (ix >= 0 && ix < classname.length() - 1)
		classname = classname.substring( ix + 1);
	outbuf.append(classname);
	outbuf.append(".");
	outbuf.append(rec.getSourceMethodName());
	outbuf.append(" ");
	outbuf.append(rec.getMessage());
	outbuf.append("\n");
	Object[] parms = rec.getParameters();
	if (parms != null && parms.length > 0) {
		for (ii = 0; ii < parms.length; ii++) {
			outbuf.append("    parm ");
			outbuf.append(Integer.toString(ii));
			outbuf.append(": ");
			if (parms[ii] == null) outbuf.append("(null)");
			else outbuf.append( parms[ii].toString());
			outbuf.append("\n");
		}
	}
	return new String( outbuf);
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:37,代碼來源:DebugLogger.java

示例6: buildParameters

import java.util.logging.LogRecord; //導入方法依賴的package包/類
private Object[] buildParameters(LogRecord record) {
    StackTraceElement frame = getCaller();

    Object[] arguments = new Object[otherPartsSize + 1];
    arguments[0] = new Long(record.getSequenceNumber());
    arguments[1] = new Date(record.getMillis());
    arguments[2] = record.getLoggerName();
    arguments[3] = record.getSourceClassName();
    arguments[4] = record.getSourceMethodName();
    if (frame != null) {
        arguments[5] = frame.getFileName();
        arguments[6] = frame.getLineNumber();
    } else {
        arguments[5] = "";
        arguments[6] = -1;
    }
    // LogRecord.getThreadID is not the actual thread ID.
    // arguments[7]=new Integer(record.getThreadID());
    arguments[7] = Thread.currentThread().getId();
    arguments[12] = Thread.currentThread().getName();

    // arguments[8]=record.getLevel().getLocalizedName();
    // this is faster, but not i18n
    arguments[8] = record.getLevel().getName();
    arguments[9] = new Integer(record.getLevel().intValue());
    arguments[11] = writeThrowable(arguments, record, 0);
    return arguments;
}
 
開發者ID:Hitachi-Data-Systems,項目名稱:Open-DM,代碼行數:29,代碼來源:DefaultFormatter.java

示例7: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:TestLogHandler.java

示例8: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public void publish(LogRecord record) {
    LogEvent event = new LogEvent(record.getSourceClassName(),
                                  record.getSourceMethodName(),
                                  record);
    PUBLISHED.add(event);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TestInferCaller.java

示例9: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public final String format(final LogRecord record) {
    final StringBuffer sb = new StringBuffer();

    date.setTime(record.getMillis());

    sb.append(sfDateOut.format(date));

    String recordName;

    if (record.getSourceClassName() != null) {
        recordName = record.getSourceClassName() + ":" + record.getSourceMethodName();
    } else {
        recordName = record.getLoggerName() + ":";
    }
    if (recordName != null) {
        sb.append(recordName);
        sb.append(":");
    }
    final String message = formatMessage(record);
    sb.append(record.getLevel().getLocalizedName());
    sb.append(": ");
    sb.append(message);
    sb.append(lineSeparator);

    if (record.getThrown() != null) {
        try {
            final StringWriter sw = new StringWriter();
            final PrintWriter pw = new PrintWriter(sw);
            record.getThrown().printStackTrace(pw);
            pw.close();
            sb.append(sw.toString());
        } catch (Exception ex) {
        }
    }
    return sb.toString();
}
 
開發者ID:openaudible,項目名稱:openaudible,代碼行數:37,代碼來源:LogFormatter.java

示例10: getPackageLogger

import java.util.logging.LogRecord; //導入方法依賴的package包/類
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;
  }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:80,代碼來源:Log.java

示例11: write

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/**
 * Formats and writes the log record the underlying stream.
 */
protected void write(LogRecord record) {
    Formatter formatter = getFormatter();
    if (formatter != null) {
        out.println(formatter.format(record));
        return;
    }
    // log name
    builder.append(record.getLoggerName());
    builder.append(" [");
    // timestamp
    calendar.setTimeInMillis(record.getMillis());
    Time.encodeForLogs(calendar, builder);
    builder.append("] ");
    // severity
    builder.append(record.getLevel().getLocalizedName());
    // class
    if (record.getSourceClassName() != null) {
        builder.append(' ');
        builder.append(record.getSourceClassName());
    }
    // method
    if (record.getSourceMethodName() != null) {
        builder.append(' ');
        builder.append(record.getSourceMethodName());
    }
    // message
    String msg = record.getMessage();
    if ((msg != null) && (msg.length() > 0)) {
        Object[] params = record.getParameters();
        if (params != null) {
            msg = String.format(msg, params);
        }
        builder.append(' ');
        builder.append(msg);
    }
    out.println(builder.toString());
    builder.setLength(0);
    // exception
    Throwable thrown = record.getThrown();
    if (thrown != null) {
        thrown.printStackTrace(out);
    }
}
 
開發者ID:a-hansen,項目名稱:alog,代碼行數:47,代碼來源:AsyncLogHandler.java

示例12: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/**
 * Format the given LogRecord.
 *
 * @param record
 *            the log record to be formatted.
 * @return a formatted log record
 */
@Override
public synchronized String format(LogRecord record) {
    StringBuilder sb = new StringBuilder();

    ZonedDateTime timestamp = ZonedDateTime.ofInstant(
            Instant.ofEpochMilli(record.getMillis()),
            ZoneId.systemDefault());

    sb.append(formatter.format(timestamp));
    sb.append(" | ");//$NON-NLS-1$

    if (record.getSourceClassName() != null) {
        sb.append(truncate(
                record.getSourceClassName().substring(
                        record.getSourceClassName().lastIndexOf('.') + 1),
                30));
    } else {
        sb.append(truncate(record.getLoggerName(), 10));
    }

    sb.append(" | "); //$NON-NLS-1$

    if (record.getSourceMethodName() != null) {
        sb.append(truncate(record.getSourceMethodName(), 30));
    }

    sb.append(" | "); //$NON-NLS-1$

    String message = formatMessage(record);
    sb.append(truncate(record.getLevel().getLocalizedName(), MAX_LEVEL_SIZE));

    sb.append(" | ");//$NON-NLS-1$

    sb.append(message);

    sb.append(System.getProperty("line.separator")); //$NON-NLS-1$
    if (record.getThrown() != null) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        record.getThrown().printStackTrace(pw);
        pw.close();
        sb.append(sw.toString());
    }
    return sb.toString();
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:53,代碼來源:LoggingFormatter.java

示例13: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public void publish(LogRecord record) {
    record.getSourceClassName(); record.getSourceMethodName();
    records.add(record);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:LoggerFinderBackendTest.java

示例14: getSourceClassName

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public String getSourceClassName(LogRecord res) {
    return res.getSourceClassName();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:LoggerFinderBackendTest.java


注:本文中的java.util.logging.LogRecord.getSourceClassName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。