Java Code Examples for java.util.logging.Logger#isLoggable()

The following examples show how to use java.util.logging.Logger#isLoggable() . 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: AbstractRefactoring.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Collects and returns a set of refactoring elements - objects that
 * will be affected by the refactoring.
 * @param session RefactoringSession that the operation will use to return
 * instances of {@link org.netbeans.modules.refactoring.api.RefactoringElement} class representing objects that
 * will be affected by the refactoring.
 * @return Chain of problems encountered or <code>null</code> in no problems
 * were found.
 */
@CheckForNull
public final Problem prepare(@NonNull RefactoringSession session) {
    try {
        Parameters.notNull("session", session); // NOI18N
        long time = System.currentTimeMillis();

        Problem p = null;
        boolean checkCalled = false;
        if (currentState < PARAMETERS_CHECK) {
            p = checkParameters();
            checkCalled = true;
        }
        if (p != null && p.isFatal()) {
            return p;
        }

        p = pluginsPrepare(checkCalled ? p : null, session);
        Logger timer = Logger.getLogger("TIMER.RefactoringPrepare");
        if (timer.isLoggable(Level.FINE)) {
            time = System.currentTimeMillis() - time;
            timer.log(Level.FINE, "refactoring.prepare", new Object[]{this, time});
        }
        return p;
    } finally {
        session.finished();
    }
}
 
Example 2
Source File: OrphanTracker.java    From brave with Apache License 2.0 5 votes vote down vote up
void log(TraceContext context, boolean allocatedButNotUsed, Throwable caller) {
  Logger logger = logger();
  if (!logger.isLoggable(logLevel)) return;
  String message = allocatedButNotUsed
      ? "Span " + context + " was allocated but never used"
      : "Span " + context + " neither finished nor flushed before GC";
  logger.log(logLevel, message, caller);
}
 
Example 3
Source File: GetRepositoryTasksCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void execute () throws CoreException, IOException, MalformedURLException {
    Logger log = Logger.getLogger(this.getClass().getName());
    if (log.isLoggable(Level.FINE)) {
        log.log(
                Level.FINE,
                "executing GetRepositoryTasksCommand for task ids {0}:{1}", //NOI18N
                new Object[] { taskRepository.getUrl(), taskIds });
    }
    if (taskIds.size() == 1 || !connector.getTaskDataHandler().canGetMultiTaskData(taskRepository)) {
        for (String taskId : taskIds) {
            TaskData taskData = connector.getTaskData(taskRepository, taskId, monitor);
            if (monitor.isCanceled()) {
                return;
            }
            if (taskData != null) {
                Accessor acc = Accessor.getInstance();
                NbTask task = acc.getOrCreateTask(taskRepository, taskData.getTaskId(), true);
                taskDataManager.putUpdatedTaskData(acc.getDelegate(task), taskData, true);
                tasks.add(task);
            }
        }
    } else {
        connector.getTaskDataHandler().getMultiTaskData(taskRepository, taskIds,
                new Collector(), monitor);
    }
}
 
Example 4
Source File: Logging.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Print the message. Currently quietly discards the Throwable.
 *
 * @param s String error message
 * @param thr Throwable stack frame
 */
public static void debugPrint(final String s, final Throwable thr)
{
	debugPrint(s);
	Logger l = getLogger();
	if (l != null && l.isLoggable(DEBUG))
	{
		thr.printStackTrace(System.err);
	}
}
 
Example 5
Source File: Logging.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Print localised information message if PCGen is debugging.
 *
 * @param message String information message (usually variable)
 * @param params Object information message (usually value)
 */
public static void debugPrintLocalised(final String message, Object... params)
{
	Logger l = getLogger();
	if (l.isLoggable(DEBUG))
	{
		String msg = LanguageBundle.getFormattedString(message, params);
		l.log(DEBUG, msg);
	}
}
 
Example 6
Source File: Logging.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void replayParsedMessages()
{
	Logger l = getLogger();
	for (QueuedMessage msg : queuedMessages)
	{
		if (l.isLoggable(msg.level))
		{
			l.log(msg.level, msg.message, msg.stackTrace);
		}

	}
	queuedMessageMark = -1;
}
 
Example 7
Source File: LoggingScopeImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * A constructor of ReefLoggingScope. It starts the timer and logs the msg
 *
 * @param logger
 * @param msg
 * @param params
 */
LoggingScopeImpl(final Logger logger, final Level logLevel, final String msg, final Object[] params) {
  this.logger = logger;
  this.logLevel = logLevel;
  this.msg = msg;
  this.params = params;
  stopWatch.start();
  this.optionalParams = Optional.ofNullable(params);

  if (logger.isLoggable(logLevel)) {
    final StringBuilder sb = new StringBuilder();
    log(sb.append(START_PREFIX).append(msg).toString());
  }
}
 
Example 8
Source File: Logging.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Beep and print error message if PCGen is debugging.
 *
 * @param s String error message
 */
public static void errorPrint(final String s)
{
	Logger l = getLogger();
	if (l.isLoggable(ERROR))
	{
		l.log(ERROR, s);
	}
}
 
Example 9
Source File: SubmitTaskCommand.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() throws CoreException, IOException, MalformedURLException {
    
    LogUtils.logBugtrackingUsage(repositoryConnector.getConnectorKind(), "ISSUE_EDIT");
    
    MylynSubmitTaskJob job = new MylynSubmitTaskJob(taskDataManager, repositoryConnector, taskRepository,
            task, taskData, changedOldAttributes);
    if (submitJobListener != null) {
        job.addSubmitJobListener(submitJobListener);
    }
    
    Logger log = Logger.getLogger(this.getClass().getName());
    if(log.isLoggable(Level.FINE)) {
        log.log(
            Level.FINE, 
            "executing SubmitJobCommand for task with id {0}:{1} ", //NOI18N
            new Object[] { task.getTaskId(), taskRepository.getUrl() });
    }
    
    job.startJob(monitor);
    IStatus status = job.getStatus();
    rr = job.getResponse();
    submittedTask = Accessor.getInstance().toNbTask(job.getTask());
    if (status != null && status != Status.OK_STATUS) {
        log.log(Level.INFO, "Command failed with status: {0}", status); //NOI18N
        if (status.getException() instanceof CoreException) {
            throw (CoreException) status.getException();
        } else {
            throw new CoreException(status);
        }
    }
}
 
Example 10
Source File: MibLogger.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 11
Source File: RequestProcessor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Place the Task to the queue of pending tasks for immediate processing.
 * If there is no other Task planned, this task is immediately processed
 * in the Processor.
 */
void enqueue(Item item) {
    Logger em = logger();
    boolean loggable = em.isLoggable(Level.FINE);
    boolean wasNull;
    
    synchronized (processorLock) {
        wasNull = item.getTask() == null;
        if (!wasNull) {
            prioritizedEnqueue(item);

            if (processors.size() < throughput) {
                Processor proc = Processor.get();
                processors.add(proc);
                if (proc.getContextClassLoader() != item.ctxLoader) {
                    if (loggable) {
                        // item classloader may be null, if the item was posted from the Finalizer thread
                        ClassLoader itemLoader = item.ctxLoader;
                        ClassLoader procLoader = proc.getContextClassLoader();
                        em.log(Level.FINE, "Setting ctxLoader for old:{0} loader:{1}#{2} new:{3} loader:{4}#{5}",
                            new Object[] {
                             proc.getName(),
                             procLoader == null ? "<none>" : procLoader.getClass().getName(),
                             procLoader == null ? "-" : Integer.toHexString(System.identityHashCode(proc.getContextClassLoader())),
                             name,
                             itemLoader == null ? "<none>" : item.ctxLoader.getClass().getName(),
                             itemLoader == null ? "-" : Integer.toHexString(System.identityHashCode(item.ctxLoader))
                            }
                        );
                    }
                    proc.setContextClassLoader(item.ctxLoader);
                }
                proc.setName(name);
                proc.attachTo(this);
            }
        }
    }
    if (loggable) {
        if (wasNull) {
            em.log(Level.FINE, "Null task for item {0}", item); // NOI18N
        } else {
            em.log(Level.FINE, "Item enqueued: {0} status: {1}", new Object[]{item.action, item.enqueued}); // NOI18N
        }
    }
}
 
Example 12
Source File: TestLogger.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 13
Source File: TestLogger.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public boolean isTraceOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINE);
}
 
Example 14
Source File: TestLogger.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 15
Source File: MibLogger.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 16
Source File: TestLogger.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 17
Source File: MibLogger.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isInfoOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.INFO);
}
 
Example 18
Source File: TestLogger.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public boolean isTraceOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINE);
}
 
Example 19
Source File: RootLevelInConfigFile.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private static void testLoggableLevels() {

        Logger foobar = Logger.getLogger("foo.bar");
        if (!foobar.isLoggable(Level.FINEST)) {
            throw new RuntimeException("Expected FINEST to be loggable in "
                    + foobar.getName());
        }
        if (!foobar.getParent().isLoggable(Level.FINEST)) {
            throw new RuntimeException("Expected FINEST to be loggable in "
                    + foobar.getName());
        }

        Logger global = Logger.getGlobal();
        if (!global.isLoggable(Level.FINEST)) {
            throw new RuntimeException("Expected FINEST to be loggable in "
                    + global.getName());
        }
        if (!global.getParent().isLoggable(Level.FINEST)) {
            throw new RuntimeException("Expected FINEST to be loggable in "
                    + global.getName());
        }

        Logger root = Logger.getLogger("");
        if (!global.isLoggable(Level.FINEST)) {
            throw new RuntimeException("Expected FINEST to be loggable in "
                    + root.getName());
        }
        if (!global.getParent().isLoggable(Level.FINEST)) {
            throw new RuntimeException("Expected FINEST to be loggable in "
                    + root.getName());
        }

        root.setLevel(Level.FINER);

        if (foobar.isLoggable(Level.FINEST)) {
            throw new RuntimeException("Didn't expect FINEST to be loggable in "
                    + foobar.getName());
        }
        if (foobar.getParent().isLoggable(Level.FINEST)) {
            throw new RuntimeException("Didn't expect FINEST to be loggable in "
                    + foobar.getName());
        }
        if (global.isLoggable(Level.FINEST)) {
            throw new RuntimeException("Didn't expect FINEST to be loggable in "
                    + global.getName());
        }
        if (global.getParent().isLoggable(Level.FINEST)) {
            throw new RuntimeException("Didn't expect FINEST to be loggable in "
                    + global.getName());
        }

        if (!foobar.isLoggable(Level.FINER)) {
            throw new RuntimeException("Expected FINER to be loggable in "
                    + foobar.getName());
        }
        if (!foobar.getParent().isLoggable(Level.FINER)) {
            throw new RuntimeException("Expected FINER to be loggable in "
                    + foobar.getName());
        }

        if (!global.isLoggable(Level.FINER)) {
            throw new RuntimeException("Expected FINER to be loggable in "
                    + global.getName());
        }
        if (!global.getParent().isLoggable(Level.FINER)) {
            throw new RuntimeException("Expected FINER to be loggable in "
                    + global.getName());
        }

    }
 
Example 20
Source File: TestLogger.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public boolean isTraceOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINE);
}