当前位置: 首页>>代码示例>>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;未经允许,请勿转载。