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


Java LogRecord.setThrown方法代碼示例

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


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

示例1: testFormat

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void testFormat() throws IOException {
    LogRecord rec = new LogRecord(Level.SEVERE, "PROBLEM");
    Throwable thrown = new NullPointerException("TESTING");
    thrown.initCause(new AssertionError("CAUSE PROBLEM"));
    rec.setThrown(thrown);
    String result = new LogFormatter().format(rec);
    assertTrue(result.contains("java.lang.NullPointerException: TESTING"));
    assertTrue(result.contains("<level>1000</level>"));
    assertTrue(result.contains("<method>testFormat</method>"));
    assertTrue(result.contains("<message>java.lang.AssertionError: CAUSE PROBLEM</message>"));
    assertTrue(result.contains("<more>"));
    assertTrue(result.contains("</more>"));
    assertTrue(result.contains(" <class>junit.framework.TestCase</class>"));
    assertTrue(result.contains("<class>sun.reflect.NativeMethodAccessorImpl</class>"));
    assertFalse(result.contains("<more>80</more>"));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:LogFormatterTest.java

示例2: testXMLFormatterDifference

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/**
 * test whether the result of LogFormatter is the same as XMLFormatter 
 * if there is no nested exception
 */
public void testXMLFormatterDifference(){
    LogRecord rec = new LogRecord(Level.SEVERE, "PROBLEM");
    LogFormatter logFormatter = new LogFormatter();
    XMLFormatter xmlFormatter = new XMLFormatter();
    String logResult = logFormatter.format(rec).replace("1000", "SEVERE");
    String xmlResult = xmlFormatter.format(rec);
    assertEquals("WITHOUT THROWABLE", xmlResult, logResult);
    rec.setThrown(new NullPointerException("TESTING EXCEPTION"));
    rec.setResourceBundleName("MUJ BUNDLE");
    logResult = logFormatter.format(rec);
    //remove file names
    logResult = logResult.replaceAll("      <file>.*</file>\n", "").replace("1000", "SEVERE");
    xmlResult = xmlFormatter.format(rec);
    assertEquals("WITH THROWABLE", xmlResult, logResult);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:LogFormatterTest.java

示例3: testLoggedExceptionIsPrinted

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void testLoggedExceptionIsPrinted() throws Exception {
    Exception ex = new IOException("Ahoj");
    LogRecord rec = new LogRecord(Level.WARNING, "Cannot process {0}");
    rec.setThrown(ex);
    rec.setParameters(new Object[] { "Jardo" });
    Logger.getLogger("global").log(rec);
    
    File[] arr = getWorkDir().listFiles();
    assertEquals("One log file", 1, arr.length);
    String s = LoggingTest.readFile(arr[0]);
    
    if (s.indexOf("Ahoj") == -1) {
        fail("There needs to be 'Ahoj':\n" + s);
    }
    if (s.indexOf("Jardo") == -1) {
        fail("There needs to be 'Jardo':\n" + s);
    }
    if (s.indexOf("testLoggedExceptionIsPrinted") == -1) {
        fail("There needs to be name of the method:\n" + s);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:LoggingExceptionTest.java

示例4: assertAccess

import java.util.logging.LogRecord; //導入方法依賴的package包/類
private LogRecord assertAccess(int index) {
    if (Children.MUTEX.isReadAccess()) {
        return null;
    }
    if (Children.MUTEX.isWriteAccess()) {
        return null;
    }
    if (!LOG.isLoggable(Level.FINE)) {
        return null;
    }
    Level level = LOG.isLoggable(Level.FINEST) ? Level.FINEST : Level.FINE;
    LogRecord rec = new LogRecord(level, "LOG_NO_READ_ACCESS"); // NOI18N
    rec.setResourceBundle(NbBundle.getBundle(VisualizerNode.class));
    rec.setParameters(new Object[] { this, index });
    rec.setLoggerName(LOG.getName());
    if (level == Level.FINEST) {
        rec.setThrown(new AssertionError(rec.getMessage()));
    }
    return rec;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:VisualizerNode.java

示例5: annotateUser

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public static void annotateUser(
    Throwable t,
    String msg,
    String locMsg,
    Throwable stackTrace,
    Date date
) {
    AnnException ex = AnnException.findOrCreate(t, true);
    LogRecord rec = new LogRecord(OwnLevel.USER, msg);
    if (stackTrace != null) {
        rec.setThrown(stackTrace);
    }
    ex.addRecord(rec);
    
    if (locMsg != null) {
        Exceptions.attachLocalizedMessage(t, locMsg);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:UIExceptions.java

示例6: testDirectlyLoggingAnExceptionWithALocalizedMessageAndTheRightLevelShowsItInADialog

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void testDirectlyLoggingAnExceptionWithALocalizedMessageAndTheRightLevelShowsItInADialog() throws Exception {
    NullPointerException npe = new NullPointerException("npe");

    LogRecord rec = new LogRecord(OwnLevel.UI, "MSG_KEY");
    rec.setThrown(npe);
    ResourceBundle b = ResourceBundle.getBundle("org/netbeans/core/NotifyExceptionBundle");
    rec.setResourceBundle(b);
    DD.toReturn = new HiddenDialog();
    Logger.global.log(rec);
    waitEQ();
    assertNotNull("We are going to display a warning", DD.lastDescriptor);
    assertTrue("We want message: " + DD.lastDescriptor, DD.lastDescriptor instanceof NotifyDescriptor.Message);
    NotifyDescriptor.Message msg = (NotifyDescriptor.Message)DD.lastDescriptor;
    assertEquals("Info msg", NotifyDescriptor.INFORMATION_MESSAGE, msg.getMessageType());
    assertEquals("Msg is localized", b.getString("MSG_KEY"), msg.getMessage());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:NotifyExceptionTest.java

示例7: log

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public void log(FrameworkEvent fe) {
    Level l = Level.FINE;
    if ((fe.getType() & FrameworkEvent.ERROR) != 0) {
        l = Level.SEVERE;
    } else if ((fe.getType() & FrameworkEvent.WARNING) != 0) {
        l = Level.WARNING;
    } else if ((fe.getType() & FrameworkEvent.INFO) != 0) {
        l = Level.INFO;
    }
    LogRecord lr = new LogRecord(l, "framework event {0} type {1}");
    lr.setParameters(new Object[]{fe.getBundle().getSymbolicName(), fe.getType()});
    lr.setThrown(fe.getThrowable());
    lr.setLoggerName(NetbinoxFactory.LOG.getName());
    NetbinoxFactory.LOG.log(lr);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:NetbinoxHooks.java

示例8: logThrowing

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/**
 * Logs throwing of exceptions.
 * 
 * @param loggerName
 * @param thrown
 */
public static void logThrowing(String loggerName, Throwable thrown) {
	if (loggerName != null) {
		Logger logger = loggers.get(loggerName);
		if (logger != null) {
			Thread current = Thread.currentThread();
			int totalStackOffset = 2;
			StackTraceElement[] trace = current.getStackTrace();

			LogRecord logRecord = new LogRecord(Level.ALL, "Exception thrown!");

			if (trace.length >= totalStackOffset) {
				StackTraceElement caller = trace[totalStackOffset];
				logRecord.setSourceMethodName(caller.getMethodName());
				logRecord.setSourceClassName(caller.getClassName());
				int lineNumber = caller.getLineNumber();
				logRecord.setParameters(new Object[] { lineNumber });
				logRecord.setThrown(thrown);
			}
			logger.log(logRecord);
		}
	}
}
 
開發者ID:CognitiveModeling,項目名稱:BrainControl,代碼行數:29,代碼來源:Logging.java

示例9: testHasNonNullName

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void testHasNonNullName() throws Exception {
    LogRecord r = new LogRecord(Level.WARNING, null);
    r.setThrown(new Exception());
    Node n = UINode.create(r);
    assertNotNull(n);
    assertNotNull(n.getName());
    assertSerializedWell(r, n);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:DecorableTest.java

示例10: doLog

import java.util.logging.LogRecord; //導入方法依賴的package包/類
protected void doLog( Level level, String key, Object[] params, Class wrapperClass,
    Throwable thr )
{
    LogRecord lrec = new LogRecord( level, key ) ;
    if (params != null)
        lrec.setParameters( params ) ;
    inferCaller( wrapperClass, lrec ) ;
    lrec.setThrown( thr ) ;
    lrec.setLoggerName( loggerName );
    lrec.setResourceBundle( logger.getResourceBundle() ) ;
    logger.log( lrec ) ;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:LogWrapperBase.java

示例11: error

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void error(String s, Throwable e) {
    LogRecord lr = new LogRecord(Level.SEVERE, s);
    lr.setSourceClassName(log.getName());
    lr.setThrown(e);

    log.log(lr);
}
 
開發者ID:xiachengwei5,項目名稱:org.mybatis.generator.core-1.3.5,代碼行數:8,代碼來源:JdkLoggingImpl.java

示例12: testHasNonNullName

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void testHasNonNullName() throws Exception {
    LogRecord r = new LogRecord(Level.WARNING, null);
    r.setThrown(new Exception());
    Node n = UINode.create(r);
    assertNotNull(n);
    assertNotNull(n.getName());
    assertSerializedWell(n);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:UINodeTest.java

示例13: testHasNonNullNameWhenMessageIsGiven

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void testHasNonNullNameWhenMessageIsGiven() throws Exception {
    Exception my = new Exception("Ahoj");
    LogRecord r = new LogRecord(Level.WARNING, my.getMessage());
    r.setThrown(my);
    Node n = UINode.create(r);
    assertNotNull(n);
    assertNotNull(n.getName());
    assertSerializedWell(n);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:UINodeTest.java

示例14: annotate

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/** Calls all delegates. */
public Throwable annotate(
    Throwable t, int severity, String message, final String localizedMessage, Throwable stackTrace,
    java.util.Date date
) {
    if (delegates.isEmpty()) {
        LogRecord rec = new LogRecord(convertSeverity(severity, true, Level.ALL), message);
        if (stackTrace != null) {
            rec.setThrown(stackTrace);
        }
        if (date != null) {
            rec.setMillis(date.getTime());
        }
        if (localizedMessage != null) {
            ResourceBundle rb = new ResourceBundle() {
                public Object handleGetObject(String key) {
                    if ("msg".equals(key)) { // NOI18N
                        return localizedMessage;
                    } else {
                        return null;
                    }
                }
                
                public Enumeration<String> getKeys() {
                    return Enumerations.singleton("msg"); // NOI18N
                }
            };
            rec.setResourceBundle(rb);
            rec.setMessage("msg"); // NOI18N
        }
        
        AnnException ann = AnnException.findOrCreate(t, true);
        if (ann != null) {  //#148778 - Although ann should not be null, it was reported it can happen.
            ann.addRecord(rec);
        }
        
        return t;
    }
    
    for (ErrorManager em : delegates) {
        em.annotate(t, severity, message, localizedMessage, stackTrace, date);
    }

    return t;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:46,代碼來源:ErrorManager.java

示例15: internalError

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
protected void internalError(String msg, Throwable cause) {
    LogRecord record = new ESLogRecord(Level.SEVERE, msg);
    record.setThrown(cause);
    logger.log(record);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:7,代碼來源:JdkESLogger.java


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