Example usage for org.apache.commons.logging Log isInfoEnabled

List of usage examples for org.apache.commons.logging Log isInfoEnabled

Introduction

In this page you can find the example usage for org.apache.commons.logging Log isInfoEnabled.

Prototype

boolean isInfoEnabled();

Source Link

Document

Is info logging currently enabled?

Usage

From source file:org.lilyproject.util.Logs.java

public static void logThreadJoin(Thread thread) {
    Log log = LogFactory.getLog("org.lilyproject.threads.join");
    if (!log.isInfoEnabled()) {
        return;//from  w  w  w  . j ava 2 s .  c o  m
    }

    String context = "";
    Exception e = new Exception();
    e.fillInStackTrace();
    StackTraceElement[] stackTrace = e.getStackTrace();
    if (stackTrace.length >= 2) {
        context = stackTrace[1].toString();
    }

    log.info("Waiting for thread to die: " + thread + " at " + context);
}

From source file:org.mule.api.processor.LoggerMessageProcessorTestCase.java

private Log buildMockLogger() {
    Log mockLogger = mock(Log.class);
    doNothing().when(mockLogger).error(any());
    doNothing().when(mockLogger).warn(any());
    doNothing().when(mockLogger).info(any());
    doNothing().when(mockLogger).debug(any());
    doNothing().when(mockLogger).trace(any());

    // All levels enabled by default
    when(mockLogger.isErrorEnabled()).thenReturn(true);
    when(mockLogger.isWarnEnabled()).thenReturn(true);
    when(mockLogger.isInfoEnabled()).thenReturn(true);
    when(mockLogger.isDebugEnabled()).thenReturn(true);
    when(mockLogger.isTraceEnabled()).thenReturn(true);
    return mockLogger;
}

From source file:org.nuxeo.datademo.tools.ToolsMisc.java

/**
 * Utility which uses <code>info()</code> if the INFO log level is enabled,
 * else log as <code>warn()</code>
 *
 * @param inLog// w  w  w . ja v a 2  s.c o  m
 * @param inWhat
 *
 * @since 7.2
 */
public static void forceLogInfo(org.apache.commons.logging.Log inLog, String inWhat) {
    if (inLog.isInfoEnabled()) {
        inLog.info(inWhat);
    } else {
        inLog.warn(inWhat);
    }
}

From source file:org.openspaces.grid.gsm.rebalancing.RebalancingUtils.java

static Collection<FutureStatelessProcessingUnitInstance> incrementNumberOfStatelessInstancesAsync(
        final ProcessingUnit pu, final GridServiceContainer[] containers, final Log logger, final long duration,
        final TimeUnit timeUnit) {

    if (pu.getMaxInstancesPerVM() != 1) {
        throw new IllegalArgumentException("Only one instance per VM is allowed");
    }//from w  ww  .j a v a  2s . c om

    List<GridServiceContainer> unusedContainers = getUnusedContainers(pu, containers);

    final Admin admin = pu.getAdmin();
    final Map<GridServiceContainer, FutureStatelessProcessingUnitInstance> futureInstances = new HashMap<GridServiceContainer, FutureStatelessProcessingUnitInstance>();

    final AtomicInteger targetNumberOfInstances = new AtomicInteger(pu.getNumberOfInstances());

    final long start = System.currentTimeMillis();
    final long end = start + timeUnit.toMillis(duration);

    for (GridServiceContainer container : unusedContainers) {
        final GridServiceContainer targetContainer = container;
        futureInstances.put(container, new FutureStatelessProcessingUnitInstance() {

            AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
            ProcessingUnitInstance newInstance;

            public boolean isTimedOut() {
                return System.currentTimeMillis() > end;
            }

            public boolean isDone() {

                end();

                return isTimedOut() || throwable.get() != null || newInstance != null;
            }

            public ProcessingUnitInstance get()
                    throws ExecutionException, IllegalStateException, TimeoutException {

                end();

                if (getException() != null) {
                    throw getException();
                }

                if (newInstance == null) {
                    if (isTimedOut()) {
                        throw new TimeoutException("Relocation timeout");
                    }
                    throw new IllegalStateException("Async operation is not done yet.");
                }

                return newInstance;
            }

            public Date getTimestamp() {
                return new Date(start);
            }

            public ExecutionException getException() {

                end();
                Throwable t = throwable.get();
                if (t != null) {
                    return new ExecutionException(t.getMessage(), t);
                }
                return null;
            }

            public GridServiceContainer getTargetContainer() {
                return targetContainer;
            }

            public ProcessingUnit getProcessingUnit() {
                return pu;
            }

            public String getFailureMessage() throws IllegalStateException {
                if (isTimedOut()) {
                    return "deployment timeout of processing unit " + pu.getName() + " on "
                            + gscToString(targetContainer);
                }

                if (getException() != null) {
                    return getException().getMessage();
                }

                throw new IllegalStateException("Relocation has not encountered any failure.");
            }

            private void end() {

                if (!targetContainer.isDiscovered()) {
                    throwable.set(new RemovedContainerProcessingUnitDeploymentException(pu, targetContainer));
                }

                else if (throwable.get() != null || newInstance != null) {
                    //do nothing. idempotent method
                }

                else {
                    incrementInstance();

                    ProcessingUnitInstance[] instances = targetContainer
                            .getProcessingUnitInstances(pu.getName());

                    if (instances.length > 0) {
                        newInstance = instances[0];
                    }
                }
            }

            private void incrementInstance() {
                final String uuid = "[incrementUid:" + UUID.randomUUID().toString() + "] ";
                int numberOfInstances = pu.getNumberOfInstances();
                int maxNumberOfInstances = getContainersOnMachines(pu).length;
                if (numberOfInstances < maxNumberOfInstances) {
                    if (targetNumberOfInstances.get() == numberOfInstances + 1) {
                        if (logger.isInfoEnabled()) {
                            logger.info("Waiting for pu.numberOfInstances to increment from "
                                    + numberOfInstances + " to " + targetNumberOfInstances.get() + ". "
                                    + "Number of relevant containers " + maxNumberOfInstances);
                        }
                    } else if (admin.getGridServiceManagers().getSize() > 1
                            && !((InternalProcessingUnit) pu).isBackupGsmInSync()) {
                        if (logger.isInfoEnabled()) {
                            logger.info("Waiting for backup gsm to sync with active gsm");
                        }
                    } else {
                        targetNumberOfInstances.set(numberOfInstances + 1);
                        if (logger.isInfoEnabled()) {
                            logger.info(uuid + " Planning to increment pu.numberOfInstances from "
                                    + numberOfInstances + " to " + targetNumberOfInstances.get() + ". "
                                    + "Number of relevant containers " + maxNumberOfInstances);
                        }
                        ((InternalAdmin) admin).scheduleAdminOperation(new Runnable() {
                            public void run() {
                                try {
                                    // this is an async operation 
                                    // pu.getNumberOfInstances() still shows the old value.
                                    pu.incrementInstance();
                                    if (logger.isInfoEnabled()) {
                                        logger.info(uuid + " pu.incrementInstance() called");
                                    }
                                } catch (AdminException e) {
                                    throwable.set(e);
                                } catch (Throwable e) {
                                    logger.error(uuid + " Unexpected Exception: " + e.getMessage(), e);
                                    throwable.set(e);
                                }
                            }
                        });
                    }
                }
            }
        });

    }

    return futureInstances.values();

}

From source file:org.pentaho.reporting.platform.plugin.ReportContentUtil.java

/**
 * Apply inputs (if any) to corresponding report parameters, care is taken when
 * checking parameter types to perform any necessary casting and conversion.
 *
 * @param report The report to retrieve parameter definitions and values from.         
 * @param context a ParameterContext for which the parameters will be under
 * @param validationResult the validation result that will hold the warnings. If null, a new one will be created.
 * @return the validation result containing any parameter validation errors.
 * @throws java.io.IOException if the report of this component could not be parsed.
 * @throws ResourceException   if the report of this component could not be parsed.
 *///from   w  ww . j a  v  a2  s .  c  o m
public static ValidationResult applyInputsToReportParameters(final MasterReport report,
        final ParameterContext context, final Map<String, Object> inputs, ValidationResult validationResult)
        throws IOException, ResourceException {
    if (validationResult == null) {
        validationResult = new ValidationResult();
    }
    // apply inputs to report
    if (inputs != null) {
        final Log log = LogFactory.getLog(SimpleReportingComponent.class);
        final ParameterDefinitionEntry[] params = report.getParameterDefinition().getParameterDefinitions();
        final ReportParameterValues parameterValues = report.getParameterValues();
        for (final ParameterDefinitionEntry param : params) {
            final String paramName = param.getName();
            try {
                final Object computedParameter = ReportContentUtil.computeParameterValue(context, param,
                        inputs.get(paramName));
                parameterValues.put(param.getName(), computedParameter);
                if (log.isInfoEnabled()) {
                    log.info(Messages.getInstance().getString("ReportPlugin.infoParameterValues", //$NON-NLS-1$
                            paramName, String.valueOf(inputs.get(paramName)),
                            String.valueOf(computedParameter)));
                }
            } catch (Exception e) {
                if (log.isWarnEnabled()) {
                    log.warn(Messages.getInstance().getString("ReportPlugin.logErrorParametrization"), e); //$NON-NLS-1$
                }
                validationResult.addError(paramName, new ValidationMessage(e.getMessage()));
            }
        }
    }
    return validationResult;
}

From source file:org.qedeq.base.trace.Trace.java

/**
 * Trace message.// ww  w. j ava2s.c  o m
 *
 * @param   tracingClass    Class that wants to make a trace entry.
 * @param   tracingObject   Instance that wants to make a trace entry.
 * @param   method          Method of that object.
 * @param   message         Message.
 */
public static void info(final Class tracingClass, final Object tracingObject, final String method,
        final String message) {
    if (traceOn) {
        final Log log = LogFactory.getFactory().getInstance(tracingClass);
        if (log.isInfoEnabled()) {
            log.info("." + method + " " + message);
        }
    }
}

From source file:org.qedeq.base.trace.Trace.java

/**
 * Trace method message./* w  ww.  ja  v  a2  s  . co m*/
 *
 * @param   tracingClass    Class that wants to make a trace entry.
 * @param   method          Method of that class.
 * @param   message         Message.
 */
public static void info(final Class tracingClass, final String method, final String message) {
    if (traceOn) {
        final Log log = LogFactory.getFactory().getInstance(tracingClass);
        if (log.isInfoEnabled()) {
            log.info("." + method + " " + message);
        }
    }
}

From source file:org.qedeq.base.trace.Trace.java

/**
 * Parameter information./*from   w w w.ja v a2s .co m*/
 *
 * @param   tracingClass    Class that wants to make a trace entry.
 * @param   tracingObject   Instance that wants to make an info entry.
 * @param   method          Method of that object.
 * @param   param           Parameter to trace.
 * @param   value           Value of parameter.
 */
public static void paramInfo(final Class tracingClass, final Object tracingObject, final String method,
        final String param, final Object value) {
    if (traceOn) {
        final Log log = LogFactory.getFactory().getInstance(tracingClass);
        if (log.isInfoEnabled()) {
            log.info("." + method + " " + param + "=" + value);
        }
    }
}

From source file:org.qedeq.base.trace.Trace.java

/**
 * Parameter information.//  ww  w  .j  a  v  a 2  s  . c om
 *
 * @param   tracingClass    Class that wants to make an info entry.
 * @param   method          Method of that class.
 * @param   param           Parameter to trace.
 * @param   value           Value of parameter.
 */
public static void paramInfo(final Class tracingClass, final String method, final String param,
        final Object value) {
    if (traceOn) {
        final Log log = LogFactory.getFactory().getInstance(tracingClass);
        if (log.isInfoEnabled()) {
            log.info("." + method + " " + param + "=" + value);
        }
    }
}

From source file:org.qedeq.base.trace.Trace.java

/**
 * Parameter information./*  w  w  w .  ja  va  2  s .  c o m*/
 * @param   tracingClass    Class that wants to make an info entry.
 * @param   tracingObject   Instance that wants to make an info entry.
 * @param   method          Method of that object.
 * @param   param           Parameter to trace.
 * @param   value           Value of parameter.
 */
public static void paramInfo(final Class tracingClass, final Object tracingObject, final String method,
        final String param, final int value) {
    if (traceOn) {
        final Log log = LogFactory.getFactory().getInstance(tracingClass);
        if (log.isInfoEnabled()) {
            log.info("." + method + " " + param + "=" + value);
        }
    }
}