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


Java LogRecord.getThrown方法代碼示例

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


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

示例1: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/**
 * Format the log record as follows:
 *
 *     Date Level Message ExceptionTrace
 *
 * @param       logRecord       The log record
 * @return                      The formatted string
 */
@Override
public String format(LogRecord logRecord) {
    Object[] arguments = new Object[4];
    arguments[0] = new Date(logRecord.getMillis());
    arguments[1] = logRecord.getLevel().getName();
    arguments[2] = logRecord.getMessage();
    Throwable exc = logRecord.getThrown();
    if (exc != null) {
        Writer result = new StringWriter();
        exc.printStackTrace(new PrintWriter(result));
        arguments[3] = result.toString();
    } else {
        arguments[3] = "";
    }
    return messageFormat.get().format(arguments);
}
 
開發者ID:muhatzg,項目名稱:burstcoin,代碼行數:25,代碼來源:BriefLogFormatter.java

示例2: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void publish(LogRecord record) {
    messages.append(record.getMessage());
    
    lastText = record.getMessage();
    lastThrowable = record.getThrown();

    Level l = record.getLevel();
    if (l.intValue() >= Level.FINEST.intValue()) {
        lastSeverity = ErrorManager.INFORMATIONAL;
    }
    if (l.intValue() >= Level.WARNING.intValue()) {
        lastSeverity = ErrorManager.WARNING;
    }
    if (l.intValue() >= Level.SEVERE.intValue()) {
        lastSeverity = ErrorManager.EXCEPTION;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ErrorManagerDelegatesToLoggingTest.java

示例3: logRecords

import java.util.logging.LogRecord; //導入方法依賴的package包/類
private void logRecords(Appendable a) {
    List<LogRecord> r = records;
    if (r == null) {
        return;
    }
    try {

        for (LogRecord log : r) {
            if (log.getMessage() != null) {
                a.append(log.getMessage()).append("\n");;
            }
            if (log.getThrown() != null) {
                StringWriter w = new StringWriter();
                log.getThrown().printStackTrace(new PrintWriter(w));
                a.append(w.toString()).append("\n");
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:UIExceptions.java

示例4: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public String format(LogRecord record) {
    StringBuilder builder = new StringBuilder();

    builder.append(DATE.format(record.getMillis()));
    builder.append(" [");
    builder.append(record.getLevel().getLocalizedName());
    builder.append("] ");
    builder.append(formatMessage(record));
    builder.append('\n');

    if (record.getThrown() != null) {
        StringWriter writer = new StringWriter();
        record.getThrown().printStackTrace(new PrintWriter(writer));
        builder.append(writer);
    }

    return builder.toString();
}
 
開發者ID:Dragovorn,項目名稱:courier,代碼行數:20,代碼來源:CourierFormatter.java

示例5: testInitFile_NotFound

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Test
public void testInitFile_NotFound() throws Exception {
  // Construct the file name but not the file
  String initFileName = temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath()
      + File.separator + INIT_FILE_NAME;

  /*
   * String historyFileName, String defaultPrompt, int historySize, String logDir, Level logLevel,
   * Integer logLimit, Integer logCount, String initFileName
   */
  GfshConfig gfshConfig = new GfshConfig(this.gfshHistoryFileName, "", 0,
      temporaryFolder_CurrentDirectory.getRoot().getAbsolutePath(), null, null, null,
      initFileName);
  assertNotNull(INIT_FILE_NAME, gfshConfig.getInitFileName());

  /*
   * boolean launchShell, String[] args, GfshConfig gfshConfig
   */
  Gfsh gfsh = Gfsh.getInstance(false, new String[] {}, gfshConfig);

  int actualStatus = gfsh.getLastExecutionStatus();
  int expectedStatus = 0;
  assertNotEquals("Status <0==failure", expectedStatus, actualStatus);

  int expectedLogCount = BANNER_LINES + INIT_FILE_CITATION_LINES + 1;
  assertEquals("Log records written", expectedLogCount, this.junitLoggerHandler.getLog().size());
  Throwable exception = null;
  for (LogRecord logRecord : this.junitLoggerHandler.getLog()) {
    if (logRecord.getThrown() != null) {
      exception = logRecord.getThrown();
      break;
    }
  }
  assertNotNull("Exceptions in log", exception);
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:36,代碼來源:GfshInitFileJUnitTest.java

示例6: log

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void log(LogRecord record) {
    init();

    errorManager.log(((Integer)levelMap.get(record.getLevel())).intValue(),
        formatter.format(record));
    
    if (record.getThrown() != null) {
        errorManager.notify(((Integer)exceptionLevelMap.get(
            record.getLevel())).intValue(), record.getThrown());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:ErrorManagerCyclicDepTest.java

示例7: toString

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public static StringBuffer toString(LogRecord record) {
    StringBuffer sb = new StringBuffer();
    sb.append('[');
    sb.append(record.getLoggerName());
    sb.append("] THREAD: ");
    sb.append(Thread.currentThread().getName());
    sb.append(" MSG: ");
    String txt = record.getMessage();
    ResourceBundle b = record.getResourceBundle();
    if (b != null) {
        try {
            txt = b.getString(txt);
        } catch (MissingResourceException ex) {
            // ignore
        }
    }
    if (txt != null && record.getParameters() != null) {
        txt = MessageFormat.format(txt, record.getParameters());
    }
    sb.append(txt);
    Throwable t = record.getThrown();
    if (t != null) {
        sb.append('\n');
        StringWriter w = new StringWriter();
        t.printStackTrace(new PrintWriter(w));
        sb.append(w.toString().replace("\tat ", "  ").replace("\t... ", "  ... "));
    }
    sb.append('\n');
    return sb;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:NbModuleLogHandler.java

示例8: 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

示例9: popLoggedThrowable

import java.util.logging.LogRecord; //導入方法依賴的package包/類
private Throwable popLoggedThrowable() {
  List<LogRecord> logRecords = logHandler.getStoredLogRecords();
  assertEquals(1, logRecords.size());
  LogRecord logRecord = logRecords.get(0);
  logHandler.clear();
  return logRecord.getThrown();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:8,代碼來源:CacheLoadingTest.java

示例10: 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();
}
 
開發者ID:drytoastman,項目名稱:scorekeeperfrontend,代碼行數:36,代碼來源:AppSetup.java

示例11: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void publish(LogRecord record) {
    if (record.getThrown() != null) {
        Level level = record.getLevel();
        if (level.intValue() == Level.WARNING.intValue() + 1) {
            // unknown level
            level = null;
        }
        if (level != null && level.intValue() == Level.SEVERE.intValue() + 1) {
            // unknown level
            level = null;
        }
        Exc ex = createExc(record.getThrown(), level, record.getLevel().intValue() == 1973 ? record : null);
        NotifyExcPanel.notify(ex);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:NbErrorManager.java

示例12: format

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public String format(LogRecord record) {
    StringBuilder sb = new StringBuilder();
    if (withTime) {
        sb.append(sdf.format(new Date(record.getMillis())) + "  ");
    }
    sb.append(record.getLevel() + "  " + formatMessage(record));
    if (record.getThrown() != null) {
        StringWriter sw = new StringWriter();
        record.getThrown().printStackTrace(new PrintWriter(sw));
        sb.append(LS + sw);
    }
    return sb.toString() + LS;
    // This uses platform-specific line-separator, the same as
    // SimpleLogger does.
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:16,代碼來源:BasicTextJdkLogFormatter.java

示例13: create

import java.util.logging.LogRecord; //導入方法依賴的package包/類
static Node create(LogRecord r) {
    Children ch;
    if (r.getThrown() != null) {
        ch = new StackTraceChildren(r.getThrown());
    } else if ("UI_ENABLED_MODULES".equals(r.getMessage()) || 
        "UI_DISABLED_MODULES".equals(r.getMessage())) {
        ch = new ModulesChildren(r.getParameters());
    } else {
        ch = Children.LEAF;
    }
    
    
    return new UINode(r, ch);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:UINode.java

示例14: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/**
 * Publishes the given LogRecord by writing its data to a file using a
 * TextFormatter.
 * 
 * @param record The {@code LogRecord} to publish.
 */
@Override
public void publish(LogRecord record) {
    if (record.getLevel().intValue() < getLevel().intValue()
        && record.getThrown() == null) {
        return;
    }

    String str = getFormatter().format(record);
    if (consoleLogging
        && record.getLevel().intValue() >= Level.WARNING.intValue()) {
        System.err.println(str);
    }

    synchronized (this.writerLock) {
        if (this.writer != null) {
            try {
                this.writer.write(str, 0, str.length());
                // Because FreeCol is still in a very early stage.
                flush();
            } catch (IOException ioe) {
                System.err.println("Failed to write log record: " + str);
                ioe.printStackTrace(System.err);
            }
        }
    }

    // Do this last, as it might shut down a debug run
    Throwable t = record.getThrown();
    if (t != null && !(t instanceof FreeColException
            && ((FreeColException)t).debugAllowed())) {
        FreeColDebugger.handleCrash();
    }
}
 
開發者ID:wintertime,項目名稱:FreeCol,代碼行數:40,代碼來源:DefaultHandler.java

示例15: getThrown

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


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