下面列出了java.util.logging.Logger#isLoggable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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());
}
}
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);
}
@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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
@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);
}
}
}
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;
}
/**
* 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);
}
}
/** 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();
}
}
public boolean isTraceOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINE);
}
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());
}
}
public boolean isTraceOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINE);
}
public boolean isInfoOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.INFO);
}
public boolean isDebugOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINEST);
}
public boolean isDebugOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINEST);
}
public boolean isDebugOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINEST);
}
public boolean isDebugOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINEST);
}
public boolean isTraceOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINE);
}
public boolean isDebugOn() {
final Logger l = getLogger();
if (l==null) return false;
return l.isLoggable(Level.FINEST);
}
/** 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
}
}
}