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

The following are Jave code examples for showing how to use isLoggable() of the java.util.logging.Logger class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: GetAttachmentCommand.java   Source Code and License Vote up 6 votes
@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 GetTaskDataCommand for attachment id: {0}", ta.getValue()); // NOI18N
    }
    AbstractTaskAttachmentHandler taskAttachmentHandler = repositoryConnector.getTaskAttachmentHandler();
    if (!taskAttachmentHandler.canGetContent(taskRepository, task)) {
        throw new IOException("Cannot get content for attachment with id: " + ta.getValue());
    }
    InputStream is = taskAttachmentHandler.getContent(taskRepository, task, ta, new NullProgressMonitor());
    try {
        byte [] buffer = new byte[4096];
        int n;
        while ((n = is.read(buffer)) != -1) {
            os.write(buffer, 0, n);
        }
    } finally {
        is.close();
    }
}
 
Example 2
Project: incubator-netbeans   File: GetMultiTaskDataCommand.java   Source Code and License Vote up 6 votes
@Override
public void execute() throws CoreException {
    
    Logger log = Logger.getLogger(this.getClass().getName());
    if(log.isLoggable(Level.FINE)) {
        log.log(
            Level.FINE, 
            "executing GetMultiTaskDataCommand for tasks: {0}", // NOI18N
            print(ids));    
    }
    
    repositoryConnector.getTaskDataHandler().getMultiTaskData(
            taskRepository,
            ids,
            collector,
            new NullProgressMonitor());
}
 
Example 3
Project: freecol   File: RandomUtils.java   Source Code and License Vote up 5 votes
/**
 * Convenience to aid logging uses of Randoms.
 *
 * @param logger The {@code Logger} to log to.
 * @param logMe A string to log with the result.
 * @param random A pseudo-{@code Random} number source.
 * @return A pseudo-random double r, 0 ≤ r < 1.0.
 */
public static float randomFloat(Logger logger, String logMe,
                                Random random) {
    float ret = random.nextFloat();
    if (logger != null && logger.isLoggable(Level.FINEST)) {
        logger.finest(logMe + " random(1.0f) = " + ret);
    }
    return ret;
}
 
Example 4
Project: incubator-netbeans   File: AbstractRefactoring.java   Source Code and License Vote up 5 votes
/** 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 5
Project: guava-mock   File: EventBus.java   Source Code and License Vote up 5 votes
@Override
public void handleException(Throwable exception, SubscriberExceptionContext context) {
  Logger logger = logger(context);
  if (logger.isLoggable(Level.SEVERE)) {
    logger.log(Level.SEVERE, message(context), exception);
  }
}
 
Example 6
Project: incubator-netbeans   File: PostAttachmentCommand.java   Source Code and License Vote up 5 votes
@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 PostTaskDataCommand for task: {0}", task.getTaskId()); // NOI18N
    }
    AbstractTaskAttachmentHandler taskAttachmentHandler = repositoryConnector.getTaskAttachmentHandler();
    if (!taskAttachmentHandler.canPostContent(taskRepository, task)) {
        throw new IOException("Cannot post attachment for task with id: " + task.getTaskId());
    }
    taskAttachmentHandler.postContent(taskRepository, task, taskAttachmentSource, comment, attAttribute, new NullProgressMonitor());
}
 
Example 7
Project: incubator-netbeans   File: GetRepositoryTasksCommand.java   Source Code and License Vote up 5 votes
@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 8
Project: Pogamut3   File: Listeners.java   Source Code and License Vote up 5 votes
/**
 * Calls notifier.notify() on each of the stored listeners, allowing you to execute stored
 * command.
 * <p><p>
 * Every notification is run inside try/catch block, exceptions are reported into the log
 * (if not null) and method returns false if some exception is thrown.
 * 
 * @param notifier
 * @param exceptionLog where to log exceptions, may be null
 * @return true, if no exception happened
 */
public boolean notifySafe(ListenerNotifier<Listener> notifier, Logger exceptionLog) {
	
	boolean noException = true;
	
	synchronized(listeners) {
		boolean listenersIterationOriginal = listenersIteration;
		listenersIteration = true;
		try {
 		Iterator<ListenerStore<Listener>> iterator = listeners.iterator();
 		while(iterator.hasNext()) {
 			ListenerStore<Listener> store = iterator.next();
 			Listener storedListener = store.getListener();
 			if (storedListener == null) {
 				if (!listenersIterationOriginal) {
 					if ((store instanceof WeakListenerStore) && log != null && log.isLoggable(Level.FINE)) {
 						log.fine((name == null ? "" : name + ": ") + "Weakly referenced listener was GC()ed.");
 					}
 					iterator.remove();
 				}
 				continue;
 			}
 			try {
 				notifier.notify(storedListener);
 			} catch (Exception e) {
 				noException = false;
 				if (exceptionLog != null) {
 					if (exceptionLog.isLoggable(Level.SEVERE)) exceptionLog.severe(ExceptionToString.process("Exception during event processing (" + notifier.getEvent() + ").", e));
 				}
 			}
 		}
		} finally {
			listenersIteration = listenersIterationOriginal;
		}
	}
	
	return noException;
}
 
Example 9
Project: incubator-netbeans   File: SimpleQueryCommand.java   Source Code and License Vote up 5 votes
@Override
public void execute () throws CoreException {
    final Logger log = Logger.getLogger(this.getClass().getName());
    if (log.isLoggable(Level.FINE)) {
        Map<String, String> attrs = query.getAttributes();
        log.log(
                Level.FINE,
                "executing SimpleQueryCommand for query {0} on repository {1} with url \n\t{2} and parameters \n\t{3}", // NOI18N
                new Object[]{query.getSummary(), taskRepository.getUrl(), query.getUrl(), attrs != null ? attrs : null});
    }
    TaskDataCollector collector = new TaskDataCollector() {
        @Override
        public void accept (TaskData taskData) {
            try {
                Accessor acc = Accessor.getInstance();
                NbTask task = acc.getOrCreateTask(taskRepository, taskData.getTaskId(), true);
                taskDataManager.putUpdatedTaskData(acc.getDelegate(task), taskData, true);
                tasks.add(task);
            } catch (CoreException ex) {
                log.log(Level.INFO, "Cannot save task data " + taskData.getTaskId(), ex);
            }
        }
    };
    status = repositoryConnector.performQuery(taskRepository, query, collector, new SynchronizationSession(), monitor);
    if (status != null && status.getSeverity() == IStatus.ERROR) {
        if (status.getException() instanceof CoreException) {
            throw (CoreException) status.getException();
        } else {
            throw new CoreException(status);
        }
    }
}
 
Example 10
Project: FreeCol   File: RandomUtils.java   Source Code and License Vote up 5 votes
/**
 * Convenience to aid logging uses of Randoms.
 *
 * @param logger The {@code Logger} to log to.
 * @param logMe A string to log with the result.
 * @param random A pseudo-{@code Random} number source.
 * @return A pseudo-random double r, 0 &le; r &lt; 1.0.
 */
public static double randomDouble(Logger logger, String logMe,
                                  Random random) {
    double ret = random.nextDouble();
    if (logger != null && logger.isLoggable(Level.FINEST)) {
        logger.finest(logMe + " random(1.0) = " + ret);
    }
    return ret;
}
 
Example 11
Project: incubator-netbeans   File: SubmitCommand.java   Source Code and License Vote up 5 votes
@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 SubmitCommand for taskData with id {0} ", // NOI18N
            data.getTaskId());
    }
    
    rr = repositoryConnector.getTaskDataHandler().postTaskData(taskRepository, data, null, new NullProgressMonitor());
    // XXX evaluate rr
}
 
Example 12
Project: FreeCol   File: RandomUtils.java   Source Code and License Vote up 5 votes
/**
 * Shuffle a list.
 *
 * @param logger The {@code Logger} to log to.
 * @param logMe A string to log with the result.
 * @param list The list.
 * @param random A random number source.
 */
public static void randomShuffle(Logger logger, String logMe,
                                 List<?> list, Random random) {
    if (list.size() <= 1 || random == null) return;
    if (logger != null && logger.isLoggable(Level.FINEST)) {
        logger.finest(logMe + " shuffle.");
    }
    Collections.shuffle(list, random);
}
 
Example 13
Project: incubator-netbeans   File: RepositoryUpdater.java   Source Code and License Vote up 5 votes
private static void reportIndexerStatistics(
        final @NonNull Logger logger,
        final @NonNull Level level,
        final @NonNull Object[] data) {
    if (logger.isLoggable(level)) {
        final LogRecord r = new LogRecord(level, "INDEXING_FINISHED"); //NOI18N
        r.setParameters(data);
        r.setResourceBundle(NbBundle.getBundle(RepositoryUpdater.class));
        r.setResourceBundleName(RepositoryUpdater.class.getPackage().getName() + ".Bundle"); //NOI18N
        r.setLoggerName(logger.getName());
        logger.log(r);
    }
}
 
Example 14
Project: incubator-netbeans   File: ProcessUtils.java   Source Code and License Vote up 5 votes
public static void logError(final Level logLevel, final Logger log, final Process p) throws IOException {
    if (log != null && log.isLoggable(logLevel)) {
        logErrorImpl(logLevel, log, readProcessError(p));
    } else {
        readAndIgnoreProcessStream(p.getErrorStream());
    }
}
 
Example 15
Project: jdk8u-jdk   File: MibLogger.java   Source Code and License Vote up 4 votes
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 16
Project: OpenJSharp   File: MibLogger.java   Source Code and License Vote up 4 votes
public boolean isTraceOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINE);
}
 
Example 17
Project: OpenJSharp   File: MibLogger.java   Source Code and License Vote up 4 votes
public boolean isConfigOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.CONFIG);
}
 
Example 18
Project: openjdk-jdk10   File: TestLogger.java   Source Code and License Vote up 4 votes
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 19
Project: OpenJSharp   File: MibLogger.java   Source Code and License Vote up 4 votes
public boolean isDebugOn() {
    final Logger l = getLogger();
    if (l==null) return false;
    return l.isLoggable(Level.FINEST);
}
 
Example 20
Project: Pogamut3   File: ProcessExecution.java   Source Code and License Vote up 4 votes
/**
 * Searches for $XXX or ${XXX} and substitute them with {@link System#getenv()} (prioritized) or {@link System#getProperty(String)}.
 * @param command
 * @return
 */
public static String substituteParams(String command, Logger log) {
	List<Tuple3<Integer, Integer, String>> params = new ArrayList<Tuple3<Integer, Integer, String>>();
	Matcher m;
	
	for (int i = 0; i < 2; ++i) {
		m = (i == 0 ? SIMPLE_PARAM.matcher(command) : FORMAL_PARAM.matcher(command));
		while (m.find()) {
			params.add(
					new Tuple3<Integer, Integer, String>(
						m.start(),          // where does the parameter start
						m.group().length(), // how long the param is
						m.group(1)          // name of the parameter matched
					)
			);
		}
	}
	
	if (params.size() == 0) return command;
	
	Collections.sort(
		params, 
		new Comparator<Tuple3<Integer, Integer, String>>() {
@Override
public int compare(Tuple3<Integer, Integer, String> o1,	Tuple3<Integer, Integer, String> o2) {
	return o2.getFirst() - o1.getFirst(); // descending order!
}
		}
	);
	
	String result = command;
	
	if (log != null && log.isLoggable(Level.INFO)) log.info("Substituing parameters for: " + command);
	
	for (Tuple3<Integer, Integer, String> param : params) {
		String paramValue = System.getenv(param.getThird());
		if (paramValue == null) {
			paramValue = System.getProperty(param.getThird());
		}
		if (paramValue == null) {
			if (log != null && log.isLoggable(Level.WARNING)) log.warning("Parameter '" + param.getThird() + "' not found! Both System.getenv(\"" + param.getThird() + "\") and System.getProperty(\"" + param.getThird() + "\") evaluates to null!");
			return null;
		}
		result = result.substring(0, param.getFirst()) + paramValue + result.substring(param.getFirst() + param.getSecond());
	}
	
	if (log != null && log.isLoggable(Level.INFO)) log.info("Substitution result: " + result);
	
	return result;
}