本文整理匯總了Java中java.util.logging.LogRecord.getSourceMethodName方法的典型用法代碼示例。如果您正苦於以下問題:Java LogRecord.getSourceMethodName方法的具體用法?Java LogRecord.getSourceMethodName怎麽用?Java LogRecord.getSourceMethodName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.logging.LogRecord
的用法示例。
在下文中一共展示了LogRecord.getSourceMethodName方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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.";
}
}
示例2: 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();
}
示例3: 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();
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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);
}
示例7: 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();
}
示例8: 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)
{
date.setTime(record.getMillis());
StringBuffer sb = new StringBuffer(dformat.format(date));
if (record.getLoggerName() != null)
sb.append(" " + record.getLoggerName());
if (record.getSourceMethodName() != null)
sb.append(" " + record.getSourceMethodName());
sb.append(" " + record.getLevel().getLocalizedName() + ": ");
sb.append(formatMessage(record).replaceAll("[\b]", ""));
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();
}
示例9: 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;
}
示例10: 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);
}
}
示例11: 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();
}
示例12: publish
import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public void publish(LogRecord record) {
record.getSourceClassName(); record.getSourceMethodName();
records.add(record);
}
示例13: getSourceMethodName
import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public String getSourceMethodName(LogRecord res) {
return res.getSourceMethodName();
}