Java Code Examples for java.util.logging.LogRecord#setResourceBundle()

The following examples show how to use java.util.logging.LogRecord#setResourceBundle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WelcomeOptions.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void setShowOnStartup( boolean show ) {
    boolean oldVal = isShowOnStartup();
    if( oldVal == show ) {
        return;
    }
    prefs().putBoolean(PROP_SHOW_ON_STARTUP, show);
    if( null != propSupport )
        propSupport.firePropertyChange( PROP_SHOW_ON_STARTUP, oldVal, show );

    LogRecord rec = new LogRecord(Level.INFO, "USG_SHOW_START_PAGE"); //NOI18N
    rec.setParameters(new Object[] {show} );
    rec.setLoggerName(Constants.USAGE_LOGGER.getName());
    rec.setResourceBundle(NbBundle.getBundle(BundleSupport.BUNDLE_NAME));
    rec.setResourceBundleName(BundleSupport.BUNDLE_NAME);

    Constants.USAGE_LOGGER.log(rec);

}
 
Example 2
Source File: LogUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void doLog(Logger log, Level level, String msg, Throwable t) {
    LogRecord record = new LogRecord(level, msg);

    record.setLoggerName(log.getName());
    record.setResourceBundleName(log.getResourceBundleName());
    record.setResourceBundle(log.getResourceBundle());

    if (t != null) {
        record.setThrown(t);
    }

    //try to get the right class name/method name - just trace
    //back the stack till we get out of this class
    StackTraceElement[] stack = (new Throwable()).getStackTrace();
    String cname = LogUtils.class.getName();
    for (int x = 0; x < stack.length; x++) {
        StackTraceElement frame = stack[x];
        if (!frame.getClassName().equals(cname)) {
            record.setSourceClassName(frame.getClassName());
            record.setSourceMethodName(frame.getMethodName());
            break;
        }
    }
    log.log(record);
}
 
Example 3
Source File: HandlerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testLoggingMessageWithBundle() throws Exception {
    FileObject dir  = TimesCollectorPeerTest.makeScratchDir(this);
    
    Logger LOG = Logger.getLogger("TIMER.instance.of.my.object");
    LogRecord rec = new LogRecord(Level.FINE, "LOG_Project"); // NOI18N
    rec.setParameters(new Object[] { dir, dir });
    rec.setResourceBundle(ResourceBundle.getBundle(HandlerTest.class.getName()));
    LOG.log(rec);

    Collection<Object> files = TimesCollectorPeer.getDefault().getFiles();
    assertEquals("One object " + files, 1, files.size());
    
    Description descr = TimesCollectorPeer.getDefault().getDescription(files.iterator().next(), "LOG_Project");
    assertNotNull(descr);
    
    if (descr.getMessage().indexOf("My Project") == -1) {
        fail("Localized msg should contain 'My Project': " + descr.getMessage());
    }
}
 
Example 4
Source File: LookupSensitiveAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void doRefresh(boolean immediate) {
    if (refreshing) {
        return;
    }
    refreshing = true;
    try {
        if (LOG.isLoggable(Level.FINER)) {
            LogRecord r = new LogRecord(Level.FINER, "LOG_ACTION_REFRESH"); // NOI18N
            r.setResourceBundle(NbBundle.getBundle(LookupSensitiveAction.class));
            r.setParameters(new Object[]{
                getClass(),
                lookup
            });
            r.setLoggerName(LOG.getName());
            LOG.log(r);
        }
        refresh(lookup, immediate);
    } finally {
        refreshing = false;
    }
    needsRefresh = false;
}
 
Example 5
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Logs feature usage.
 *
 * @param srcClass source class
 * @param message message key
 * @param params message parameters, may be <code>null</code>
 */
public static void logUsage(Class srcClass, String message, Object[] params) {
    Parameters.notNull("message", message);

    LogRecord logRecord = new LogRecord(Level.INFO, message);
    logRecord.setLoggerName(USG_LOGGER.getName());
    logRecord.setResourceBundle(NbBundle.getBundle(srcClass));
    logRecord.setResourceBundleName(srcClass.getPackage().getName() + ".Bundle"); // NOI18N
    if (params != null) {
        logRecord.setParameters(params);
    }
    USG_LOGGER.log(logRecord);
}
 
Example 6
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Logs usage data.
 *
 * @param srcClass source class
 * @param message message key
 * @param params message parameters, may be <code>null</code>
 */
public static void logUsage(Class srcClass, String message, Object[] params) {
    Parameters.notNull("message", message); // NOI18N

    LogRecord logRecord = new LogRecord(Level.INFO, message);
    logRecord.setLoggerName(USG_LOGGER.getName());
    logRecord.setResourceBundle(NbBundle.getBundle(srcClass));
    logRecord.setResourceBundleName(srcClass.getPackage().getName() + ".Bundle"); // NOI18N
    if (params != null) {
        logRecord.setParameters(params);
    }
    USG_LOGGER.log(logRecord);
}
 
Example 7
Source File: ResourceInternationalString.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Converts this international string to a log record.
 *
 * @param  level  the logging level.
 * @return a log record with the message of this international string.
 *
 * @since 1.0
 */
public final LogRecord toLogRecord(final Level level) {
    final LogRecord record = new LogRecord(level, getKeyConstants().getKeyName(key));
    final IndexedResourceBundle resources = getBundle(null);
    record.setResourceBundleName(resources.getClass().getName());
    record.setResourceBundle(resources);
    if (hasArguments) {
        record.setParameters(resources.toArray(arguments));
    }
    return record;
}
 
Example 8
Source File: LinkButton.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void logUsage() {
    LogRecord rec = new LogRecord(Level.INFO, "USG_START_PAGE_LINK"); //NOI18N
    String id = usageTrackingId;
    if( null == id )
        id = getText();
    rec.setParameters(new Object[] {id} );
    rec.setLoggerName(Constants.USAGE_LOGGER.getName());
    rec.setResourceBundle(NbBundle.getBundle(BundleSupport.BUNDLE_NAME));
    rec.setResourceBundleName(BundleSupport.BUNDLE_NAME);

    Constants.USAGE_LOGGER.log(rec);
    System.err.println("usage: " + id);
}
 
Example 9
Source File: UsageLogging.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static LogRecord createLogRecord(ResourceBundle bundle, String message, Object... params) {
    LogRecord logRecord = new LogRecord(Level.INFO, message);
    logRecord.setResourceBundle(bundle);
    if (params != null) {
        logRecord.setParameters(params);
    }
    return logRecord;
}
 
Example 10
Source File: EarProjectUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Logs feature usage.
 *
 * @param srcClass source class
 * @param message message key
 * @param params message parameters, may be <code>null</code>
 */
public static void logUsage(Class srcClass, String message, Object[] params) {
    Parameters.notNull("message", message);

    LogRecord logRecord = new LogRecord(Level.INFO, message);
    logRecord.setLoggerName(USG_LOGGER.getName());
    logRecord.setResourceBundle(NbBundle.getBundle(srcClass));
    logRecord.setResourceBundleName(srcClass.getPackage().getName() + ".Bundle"); // NOI18N
    if (params != null) {
        logRecord.setParameters(params);
    }
    USG_LOGGER.log(logRecord);
}
 
Example 11
Source File: GestureSubmitter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void logUsage(String startType, List<Object> params) {
    LogRecord record = new LogRecord(Level.INFO, "USG_PROFILER_" + startType); // NOI18N
    record.setResourceBundle(NbBundle.getBundle(GestureSubmitter.class));
    record.setResourceBundleName(GestureSubmitter.class.getPackage().getName() + ".Bundle"); // NOI18N
    record.setLoggerName(USG_LOGGER.getName());
    record.setParameters(params.toArray(new Object[0]));

    USG_LOGGER.log(record);
}
 
Example 12
Source File: AbstractDelegatingLogger.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void doLog(LogRecord lr, String rbname) {
    lr.setLoggerName(getName());
    if (rbname != null) {
        lr.setResourceBundleName(rbname);
        lr.setResourceBundle(loadResourceBundle(rbname));
    }
    internalLog(lr);
}
 
Example 13
Source File: LogWrapperBase.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 ) ;
}
 
Example 14
Source File: LogAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")  // setMillis is deprecated in JDK 9
protected Object writeReplace() {
	LogRecord serialized = new LogRecord(getLevel(), getMessage());
	serialized.setLoggerName(getLoggerName());
	serialized.setResourceBundle(getResourceBundle());
	serialized.setResourceBundleName(getResourceBundleName());
	serialized.setSourceClassName(getSourceClassName());
	serialized.setSourceMethodName(getSourceMethodName());
	serialized.setSequenceNumber(getSequenceNumber());
	serialized.setParameters(getParameters());
	serialized.setThreadID(getThreadID());
	serialized.setMillis(getMillis());
	serialized.setThrown(getThrown());
	return serialized;
}
 
Example 15
Source File: LogUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void log(String message, Object[] params) {
    Parameters.notNull("params", params); // NOI18N
    LogRecord logRecord = new LogRecord(Level.INFO, message);
    logRecord.setLoggerName(USG_LOGGER_WEBSVC.getName());
    logRecord.setResourceBundle(NbBundle.getBundle(LogUtils.class));
    logRecord.setResourceBundleName(LogUtils.class.getPackage().getName() + ".Bundle"); // NOI18N
    if (params != null) {
        logRecord.setParameters(params);
    }
    USG_LOGGER_WEBSVC.log(logRecord);
}
 
Example 16
Source File: LogWrapperBase.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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 ) ;
}
 
Example 17
Source File: ProjectAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void runSequentially(final Queue<Project> queue, final LookupSensitiveAction a, final String command) {
    Project p = queue.remove();
    final ActionProvider ap = p.getLookup().lookup(ActionProvider.class);
    if (ap == null) {
        return;
    }
    if (!Arrays.asList(ap.getSupportedActions()).contains(command)) {
        // #47160: was a supported command (e.g. on a freeform project) but was then removed.
        Utilities.disabledActionBeep();
        a.resultChanged(null);
        return;
    }
    LogRecord r = new LogRecord(Level.FINE, "PROJECT_ACTION"); // NOI18N
    r.setResourceBundle(NbBundle.getBundle(ProjectAction.class));
    r.setParameters(new Object[] {
        a.getClass().getName(),
        p.getClass().getName(),
        a.getValue(NAME)
    });
    r.setLoggerName(UILOG.getName());
    UILOG.log(r);
    Mutex.EVENT.writeAccess(new Runnable() {
        @Override public void run() {
            final AtomicBoolean started = new AtomicBoolean();
            ap.invokeAction(command, Lookups.singleton(new ActionProgress() {
                @Override protected void started() {
                    started.set(true);
                }
                @Override public void finished(boolean success) {
                    if (success && !queue.isEmpty()) { // OK, next...
                        runSequentially(queue, a, command);
                    } else { // stopping now; restore natural action enablement state
                        a.resultChanged(null);
                    }
                }
            }));
            if (started.get()) {
                a.setEnabled(false);
            } else if (!queue.isEmpty()) {
                // Did not run action for some reason; try others?
                runSequentially(queue, a, command);
            }
        }
    });
}
 
Example 18
Source File: LogRecords.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (current != null) {
        String v = chars.toString();
        values.put(current, v);
        if (current == Elem.PARAM) {
            if (params == null) {
                params = new ArrayList<String>();
            }
            params.add(v);
            if (params.size() > 1500) {
                LOG.severe("Too long params when reading a record. Deleting few. Msg: " + Elem.MESSAGE.parse(values)); // NOI18N
                for (String p : params) {
                    LOG.fine(p);
                }
                params.clear();
            }
        }
    }
    current = null;
    chars = new StringBuilder();
    
    if (currentEx != null && currentEx.values != null) {
        if ("frame".equals(qName)) { // NOI18N
            String line = Elem.LINE.parse(values);
            StackTraceElement elem = new StackTraceElement(
                    Elem.CLASS.parse(values),
                    Elem.METHOD.parse(values),
                    Elem.FILE.parse(values),
                    line == null ? -1 : Integer.parseInt(line)
                    );
            currentEx.trace.add(elem);
            values.remove(Elem.CLASS);
            values.remove(Elem.METHOD);
            values.remove(Elem.LINE);
        }
        if ("exception".equals(qName)) {
            currentEx.message = values.get(Elem.MESSAGE);
            String more = values.get(Elem.MORE);
            if (more != null) currentEx.more = Integer.parseInt(more);
            if (exceptions == null){
                exceptions = new ArrayDeque<FakeException>();
            }
            exceptions.add(currentEx);
            values = currentEx.values;
            currentEx = null;
        }
        return;
    }
    
    if ("record".equals(qName)) { // NOI18N
        String millis = Elem.MILLIS.parse(values);
        String seq = Elem.SEQUENCE.parse(values);
        String lev = Elem.LEVEL.parse(values);
        String thread = Elem.THREAD.parse(values);
        String msg = Elem.MESSAGE.parse(values);
        String key = Elem.KEY.parse(values);
        String catalog = Elem.CATALOG.parse(values);
        
        if (lev != null) {
            LogRecord r = new LogRecord(parseLevel(lev), key != null && catalog != null ? key : msg);
            try {
                r.setThreadID(parseInt(thread));
            } catch (NumberFormatException ex) {
                LOG.log(Level.WARNING, ex.getMessage(), ex);
            }
            r.setSequenceNumber(parseLong(seq));
            r.setMillis(parseLong(millis));
            r.setResourceBundleName(key);
            if (catalog != null && key != null) {
                r.setResourceBundleName(catalog);
                if (!"<null>".equals(catalog)) { // NOI18N
                    try {
                        ResourceBundle b = NbBundle.getBundle(catalog);
                        b.getObject(key);
                        // ok, the key is there
                        r.setResourceBundle(b);
                    } catch (MissingResourceException e) {
                        LOG.log(Level.CONFIG, "Cannot find resource bundle {0} for key {1}", new Object[] { catalog, key });
                        r.setResourceBundle(new FakeBundle(key, msg));
                    }
                } else {
                    LOG.log(Level.CONFIG, "Cannot find resource bundle <null> for key {1}", key);
                }
            }
            if (params != null) {
                r.setParameters(params.toArray());
            }
            if (exceptions != null) {
                r.setThrown(createThrown(null));
                // exceptions = null;  should be empty after poll
            }

            callback.publish(r);
        }

        currentEx = null;
        params = null;
        values.clear();
    }
    
}
 
Example 19
Source File: AbstractEditorAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public final void actionPerformed(final ActionEvent evt) {
    // Possibly delegate to getDelegateAction()
    Action dAction = getDelegateAction();
    if (dAction != null) {
        if (!(dAction instanceof AbstractEditorAction)) {
            checkTogglePreferencesValue();
        }
        dAction.actionPerformed(evt);
        return;
    }

    final JTextComponent component = getTextComponent(evt);
    MacroRecording.get().recordAction(this, evt, component); // Possibly record action in a currently recorded macro

    if (UILOG.isLoggable(Level.FINE)) {
        // TODO [Mila] - Set action's property to disable UI logging
        String actionName = actionName();
        Boolean logged = LOGGED_ACTION_NAMES.get(actionName);
        if (logged == null) {
            logged = isLogged(actionName);
            LOGGED_ACTION_NAMES.put(actionName, logged);
        }
        if (logged) {
            LogRecord r = new LogRecord(Level.FINE, "UI_ACTION_EDITOR"); // NOI18N
            r.setResourceBundle(NbBundle.getBundle(AbstractEditorAction.class));
            if (evt != null) {
                r.setParameters(new Object[] { evt, evt.toString(), this, toString(), getValue(NAME) });
            } else {
                r.setParameters(new Object[] { "no-ActionEvent", "no-ActionEvent", this, toString(), getValue(NAME) }); //NOI18N
            }
            r.setLoggerName(UILOG.getName());
            UILOG.log(r);
        }
    }

    checkTogglePreferencesValue();

    if (asynchronous()) {
        RequestProcessor.getDefault().post(new Runnable () {
            public void run() {
                actionPerformed(evt, component);
            }
        });
    } else {
        actionPerformed(evt, component);
    }
}
 
Example 20
Source File: IndexedResourceBundle.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Gets a localized log record.
 *
 * @param  level  the log record level.
 * @param  key    the resource key.
 * @return the log record.
 */
public final LogRecord getLogRecord(final Level level, final short key) {
    final LogRecord record = new LogRecord(level, getKeyConstants().getKeyName(key));
    record.setResourceBundleName(getClass().getName());
    record.setResourceBundle(this);
    return record;
}