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


Java LogRecord.getResourceBundle方法代碼示例

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


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

示例1: getLocalizedMessage

import java.util.logging.LogRecord; //導入方法依賴的package包/類
/** Extracts localized message from a LogRecord */
private static final String getLocalizedMessage(LogRecord rec) {
    ResourceBundle rb = rec.getResourceBundle();
    if (rb == null) {
        return null;
    }
    
    String msg = rec.getMessage();
    if (msg == null) {
        return null;
    }
    
    String format = rb.getString(msg);

    Object[] arr = rec.getParameters();
    if (arr == null) {
        return format;
    }

    return MessageFormat.format(format, arr);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:NbErrorManager.java

示例2: extractLocalizedMessage

import java.util.logging.LogRecord; //導入方法依賴的package包/類
private static String extractLocalizedMessage(final Throwable t) {
    String msg = null;
    if (t instanceof Callable) {
        Object res = null;
        try {
            res = ((Callable) t).call();
        } catch (Exception ex) {
            LOG.log(Level.WARNING, null, t); // NOI18N
        }
        if (res instanceof LogRecord[]) {
            for (LogRecord r : (LogRecord[])res) {
                ResourceBundle b = r.getResourceBundle();
                if (b != null) {
                    msg = b.getString(r.getMessage());
                    break;
                }
            }
        }
    }
    return msg;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:Exceptions.java

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

示例4: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
public void publish(LogRecord rec) {
    String message = rec.getMessage();
    if (rec.getResourceBundle() != null) {
        try {
            message = rec.getResourceBundle().getString(rec.getMessage());
            if (rec.getParameters() != null) {
                message = MessageFormat.format(message, rec.getParameters());
            }
        } catch (MissingResourceException ex) {
            Logger.getAnonymousLogger().log(Level.INFO, null, ex);
        }
    }

    Object[] args = rec.getParameters();
    if (args == null || args[0] == null) return;
    
    if (args.length == 1) { // simplified instance logging
        TimesCollectorPeer.getDefault().reportReference(
                INSTANCES, rec.getMessage(), message, args[0]);
        return;
    }
    
    if (args.length < 2) {
        return;
    }
    
    Object key = args[0];

    if (args[1] instanceof Number) { // time
        TimesCollectorPeer.getDefault().reportTime(
                key, rec.getMessage(), message, ((Number)args[1]).longValue());
    } else if (args[1] instanceof Boolean) { // start/stop logic
        // XXX - start/stop support
    } else {
        String txt = message.startsWith("[M]") ? message : "[M] " + message;
        TimesCollectorPeer.getDefault().reportReference(
                key, rec.getMessage(), txt, args[1]);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:40,代碼來源:Install.java

示例5: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public void publish(LogRecord record) {
    lastBundle = record.getResourceBundle();
    lastBundleName = record.getResourceBundleName();
    lastParams = record.getParameters();
    lastThrown = record.getThrown();
    lastMessage = record.getMessage();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TestLogrbResourceBundle.java

示例6: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public synchronized void publish(LogRecord record) {
    Object[] params = record.getParameters();
    // Each GetRB thread has its own handler, but since they
    // log into the same logger, each handler may receive
    // messages emitted by other threads.
    // This means that GetRB#2.handler may receive a message
    // emitted by GetRB#1 at a time where the resource bundle
    // was still null.
    // To avoid falling into this trap, the GetRB thread passes
    // 'this' as argument to the messages it logs - which does
    // allow us here to ignore messages that where not emitted
    // by our own GetRB.this thread...
    if (params.length == 1) {
        if (params[0] == GetRB.this) {
            // The message was emitted by our thread.
            count++;
            rb = record.getResourceBundle();
            rbName = record.getResourceBundleName();
        } else {
            // The message was emitted by another thread: just
            // ignore it, as it may have been emitted at a time
            // where the resource bundle was still null, and
            // processing it may overwrite the 'rb' and 'rbName'
            // recorded from the message emitted by our own thread.
            if (VERBOSE) {
                System.out.println("Ignoring message logged by " + params[0]);
            }
            ignoreLogCount.incrementAndGet();
        }
    } else {
        ignoreLogCount.incrementAndGet();
        System.err.println("Unexpected message received");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:36,代碼來源:TestLoggerBundleSync.java

示例7: publish

import java.util.logging.LogRecord; //導入方法依賴的package包/類
@Override
public void publish(LogRecord record) {
    lastBundle = record.getResourceBundle();
    lastBundleName = record.getResourceBundleName();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:TestSetResourceBundle.java

示例8: getResourceBundle

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


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