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:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the given message to the log at the info level. If the log level is not enabled, this method does
 * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned.
 *
 * <p>The given Throwable will be passed to the logger so its stack can be dumped when appropriate.</p>
 *
 * @param  log       the log where the messages will go
 * @param  throwable the throwable associated with the log message
 * @param  basename  the base name of the resource bundle
 * @param  locale    the locale to determine what bundle to use
 * @param  key       the resource bundle key name
 * @param  varargs   arguments to help fill in the resource bundle message
 *
 * @return if the message was logged, a non-<code>null</code> Msg object is returned
 *//*from ww w  .  j a va 2 s. c om*/
public static Msg info(Log log, Throwable throwable, BundleBaseName basename, Locale locale, String key,
        Object... varargs) {
    if (log.isInfoEnabled()) {
        Msg msg = Msg.createMsg(basename, locale, key, varargs);
        logInfoWithThrowable(log, key, msg, throwable);
        return msg;
    }

    return null;
}

From source file:com.amazon.carbonado.repo.tupl.LogEventListener.java

@Override
public void notify(EventType type, String message, Object... args) {
    int intLevel = type.level.intValue();

    Log log = mLog;
    if (log != null) {
        if (intLevel <= Level.INFO.intValue()) {
            if (type.category == EventType.Category.CHECKPOINT) {
                if (log.isDebugEnabled()) {
                    log.debug(format(type, message, args));
                }/*  w w w.j a va 2  s .  c o m*/
            } else if (log.isInfoEnabled()) {
                log.info(format(type, message, args));
            }
        } else if (intLevel <= Level.WARNING.intValue()) {
            if (log.isWarnEnabled()) {
                log.warn(format(type, message, args));
            }
        } else if (intLevel <= Level.SEVERE.intValue()) {
            if (log.isFatalEnabled()) {
                log.fatal(format(type, message, args));
            }
        }
    }

    if (intLevel > Level.WARNING.intValue() && mPanicHandler != null) {
        mPanicHandler.onPanic(mDatabase, type, message, args);
    }
}

From source file:dk.statsbiblioteket.util.Logs.java

/**
 * Log the message and the elements to the log at the specified level.
 * Elements are converted to Strings and appended to the message. Arrays,
 * Lists and similar in the elements are expanded to a certain degree of
 * detail./*ww w .j a  v a 2s .  c o  m*/
 *
 * Sample input/output:
 * <code>log(myLog, Level.TRACE, false, "Started test", null,
 * 5, new String[]{"flim", "flam"});</code>
 * expands to
 * <code>log.trace("Started test (5, (flim, flam))");</code>
 *
 * @param log      the log to log to.
 * @param level    the level to log to (e.g. TRACE, DEBUG, INFO...).
 * @param verbose  if true, the elements are expanded more than for false.
 * @param error    the cause of this logging. If null, no cause is logged.
 * @param message  the message for the log.
 * @param elements the elements to log.
 */
public static void log(Log log, Level level, String message, Throwable error, boolean verbose,
        Object... elements) {
    int maxLength = verbose ? VERBOSE_MAXLENGTH : DEFAULT_MAXLENGTH;
    int maxDepth = verbose ? VERBOSE_MAXDEPTH : DEFAULT_MAXDEPTH;
    String expanded = message;
    if (elements != null && elements.length > 0) {
        expanded += expand(elements, maxLength, maxDepth);
    }
    switch (level) {
    case TRACE:
        if (!log.isTraceEnabled()) {
            return;
        }
        if (error == null) {
            log.trace(expanded);
        } else {
            log.trace(expanded, error);
        }
        break;
    case DEBUG:
        if (!log.isDebugEnabled()) {
            return;
        }
        if (error == null) {
            log.debug(expanded);
        } else {
            log.debug(expanded, error);
        }
        break;
    case INFO:
        if (!log.isInfoEnabled()) {
            return;
        }
        if (error == null) {
            log.info(expanded);
        } else {
            log.info(expanded, error);
        }
        break;
    case WARN:
        if (!log.isWarnEnabled()) {
            return;
        }
        if (error == null) {
            log.warn(expanded);
        } else {
            log.warn(expanded, error);
        }
        break;
    case ERROR:
        if (!log.isErrorEnabled()) {
            return;
        }
        if (error == null) {
            log.error(expanded);
        } else {
            log.error(expanded, error);
        }
        break;
    case FATAL:
        if (!log.isFatalEnabled()) {
            return;
        }
        if (error == null) {
            log.fatal(expanded);
        } else {
            log.fatal(expanded, error);
        }
        break;
    default:
        throw new IllegalArgumentException("The level '" + level + "' is unknown");
    }
}

From source file:com.springframework.core.annotation.AnnotationUtils.java

/**
 * Log an introspection failure (in particular {@code TypeNotPresentExceptions}) -
 * before moving on, pretending there were no annotations on this specific element.
 * @param element the element that we tried to introspect annotations on
 * @param ex the exception that we encountered
 *///from   ww  w.j a va 2 s .  co  m
static void logIntrospectionFailure(AnnotatedElement element, Exception ex) {
    Log loggerToUse = logger;
    if (loggerToUse == null) {
        loggerToUse = LogFactory.getLog(AnnotationUtils.class);
        logger = loggerToUse;
    }
    if (element instanceof Class && Annotation.class.isAssignableFrom((Class<?>) element)) {
        // Meta-annotation lookup on an annotation type
        if (logger.isDebugEnabled()) {
            logger.debug("Failed to introspect meta-annotations on [" + element + "]: " + ex);
        }
    } else {
        // Direct annotation lookup on regular Class, Method, Field
        if (loggerToUse.isInfoEnabled()) {
            logger.info("Failed to introspect annotations on [" + element + "]: " + ex);
        }

    }
}

From source file:com.amazon.carbonado.repo.indexed.IndexedStorage.java

@SuppressWarnings("unchecked")
private void removeIndex(StorableIndex index) throws RepositoryException {
    Log log = LogFactory.getLog(IndexedStorage.class);
    if (log.isInfoEnabled()) {
        StringBuilder b = new StringBuilder();
        b.append("Removing index on ");
        b.append(getStorableType().getName());
        b.append(": ");
        try {//from   w  w  w .ja  va  2s  . c  om
            index.appendTo(b);
        } catch (java.io.IOException e) {
            // Not gonna happen.
        }
        log.info(b.toString());
    }

    Class<? extends Storable> indexEntryClass = IndexEntryGenerator.getIndexAccess(index).getReferenceClass();

    Storage<?> indexEntryStorage;
    try {
        indexEntryStorage = mRepository.getIndexEntryStorageFor(indexEntryClass);
    } catch (Exception e) {
        // Assume it doesn't exist.
        unregisterIndex(index);
        return;
    }

    {
        // Doesn't completely remove the index, but it should free up space.

        double desiredSpeed = mRepository.getIndexRepairThrottle();
        Throttle throttle = desiredSpeed < 1.0 ? new Throttle(BUILD_THROTTLE_WINDOW) : null;

        if (throttle == null) {
            indexEntryStorage.truncate();
        } else {
            long totalDropped = 0;
            while (true) {
                Transaction txn = mRepository.getWrappedRepository()
                        .enterTopTransaction(IsolationLevel.READ_COMMITTED);
                txn.setForUpdate(true);
                try {
                    Cursor<? extends Storable> cursor = indexEntryStorage.query().fetch();
                    if (!cursor.hasNext()) {
                        break;
                    }
                    int count = 0;
                    final long savedTotal = totalDropped;
                    boolean anyFailure = false;
                    try {
                        while (count++ < BUILD_BATCH_SIZE && cursor.hasNext()) {
                            if (cursor.next().tryDelete()) {
                                totalDropped++;
                            } else {
                                anyFailure = true;
                            }
                        }
                    } finally {
                        cursor.close();
                    }
                    txn.commit();
                    if (log.isInfoEnabled()) {
                        log.info("Removed " + totalDropped + " index entries");
                    }
                    if (anyFailure && totalDropped <= savedTotal) {
                        log.warn("No indexes removed in last batch. " + "Aborting index removal cleanup");
                        break;
                    }
                } catch (FetchException e) {
                    throw e.toPersistException();
                } finally {
                    txn.exit();
                }

                try {
                    throttle.throttle(desiredSpeed, BUILD_THROTTLE_SLEEP_PRECISION);
                } catch (InterruptedException e) {
                    throw new RepositoryException("Index removal interrupted");
                }
            }
        }
    }

    unregisterIndex(index);
}

From source file:de.ingrid.iplug.csw.dsc.cache.impl.AbstractUpdateStrategy.java

/**
 * Process a fetched search result (collect ids and cache records)
 * /*from   w  ww . ja v  a 2  s .c  o m*/
 * @param result The search result
 * @param doCache Determines wether to cache the record or not
 * @return The list of ids of the fetched records
 * @throws Exception
 */
private List<String> processResult(CSWSearchResult result, boolean doCache) throws Exception {

    Cache cache = this.getExecutionContext().getCache();
    Log log = this.getLog();

    List<String> fetchedRecordIds = new ArrayList<String>();
    for (CSWRecord record : result.getRecordList()) {
        String id = record.getId();

        if (log.isInfoEnabled())
            log.info("Fetched record: " + id + " " + record.getElementSetName());
        if (fetchedRecordIds.contains(id)) {
            log.warn("Duplicated id: " + id + ". Overriding previous entry.");
        }
        fetchedRecordIds.add(id);

        // cache only if requested
        if (doCache)
            cache.putRecord(record);
    }
    if (log.isInfoEnabled())
        log.info("Fetched " + fetchedRecordIds.size() + " of " + result.getNumberOfRecordsTotal()
                + " [starting from " + result.getQuery().getStartPosition() + "]");
    return fetchedRecordIds;
}

From source file:com.microsoft.tfs.client.common.framework.command.TeamExplorerLogCommandFinishedCallback.java

@Override
public void onCommandFinished(final ICommand command, IStatus status) {
    /*/*from   w w  w.j a va  2 s . c o  m*/
     * Team Explorer ("private") logging. Map IStatus severity to commons
     * logging severity iff the severity is greater than the configured
     * tfsLogMinimumSeverity.
     */
    if (status.getSeverity() >= minimumSeverity) {
        /*
         * UncaughtCommandExceptionStatus is a TeamExplorerStatus, which
         * does a silly trick: it makes the exception it was given
         * accessible only through a non-standard method. This helps when
         * displaying the status to the user in a dialog, but prevents the
         * platform logger from logging stack traces, so fix it up here.
         *
         * The right long term fix is to ditch TeamExplorerStatus entirely.
         */
        if (status instanceof TeamExplorerStatus) {
            status = ((TeamExplorerStatus) status).toNormalStatus();
        }

        /*
         * Don't have a static Log for this class, because then the errors
         * show up as coming from this class, which is not correct. Instead,
         * get the logger for the class the errors originated from. Note
         * that this is not a particularly expensive operation - it looks up
         * the classname in a hashmap. This should be more than suitable for
         * a command finished error handler.
         */
        final Log log = LogFactory.getLog(CommandHelpers.unwrapCommand(command).getClass());

        if (status.getSeverity() == IStatus.ERROR && log.isErrorEnabled()) {
            log.error(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException());
        } else if (status.getSeverity() == IStatus.WARNING && log.isWarnEnabled()) {
            log.error(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException());
        } else if (status.getSeverity() == IStatus.INFO && log.isInfoEnabled()) {
            log.info(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException());
        } else if (status.getSeverity() == IStatus.CANCEL && log.isInfoEnabled()) {
            log.info(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException());
        } else if (status.getSeverity() != IStatus.OK && log.isDebugEnabled()) {
            log.debug(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException());
        } else if (log.isTraceEnabled()) {
            log.trace(CommandFinishedCallbackHelpers.getMessageForStatus(status), status.getException());
        }
    }
}

From source file:it.caladyon.akka.commonslog.CommonsLoggingLogger.java

@Override
public void onReceive(Object message) throws Exception {
    if (message instanceof InitializeLogger) {
        loggerLog.info(message);//w  w  w .  j  a v a 2s .c  om
        getSender().tell(Logging.loggerInitialized(), getSelf());
    } else if (message instanceof Error) {
        Log log = LogFactory.getLog(((Error) message).logClass());
        if (((Error) message).cause() == null) {
            log.error(composeMessage((LogEvent) message));
        } else {
            log.error(composeMessage((LogEvent) message), ((Error) message).cause());
        }
    } else if (message instanceof Warning) {
        Log log = LogFactory.getLog(((Warning) message).logClass());
        log.warn(composeMessage((LogEvent) message));
    } else if (message instanceof Info) {
        Log log = LogFactory.getLog(((Info) message).logClass());
        if (log.isInfoEnabled()) {
            log.info(composeMessage((LogEvent) message));
        }
    } else if (message instanceof Debug) {
        Log log = LogFactory.getLog(((Debug) message).logClass());
        if (log.isDebugEnabled()) {
            log.debug(composeMessage((LogEvent) message));
        }
    }
}

From source file:interactivespaces.activity.component.route.ros.RosMessageRouterActivityComponent.java

@Override
public void shutdownComponent() {
    running = false;/*from w  w  w  . ja v  a 2  s. co m*/

    Log log = getComponentContext().getActivity().getLog();
    log.info("Shutting down ROS message router activity component");

    long timeStart = System.currentTimeMillis();

    clearAllChannelTopics();

    if (log.isInfoEnabled()) {
        log.info(String.format("ROS message router activity component shut down in %d msecs",
                System.currentTimeMillis() - timeStart));
    }
}

From source file:hotbeans.support.AbstractHotBeanModuleRepository.java

/**
 * Destroys this AbstractHotBeanModuleRepository. Subclasses may override this method, but should call the super
 * class implementation./*from w ww .  j  av  a2 s  . co m*/
 */
public void destroy() throws Exception {
    Log logger = this.getLog();

    synchronized (this.lock) {
        String[] moduleNames = this.getHotBeanModuleNames();
        if (logger.isInfoEnabled())
            logger.info("Destroying " + this.getName() + " (" + ((moduleNames != null) ? moduleNames.length : 0)
                    + " modules).");
        HotBeanModuleType moduleType;
        HotBeanModule[] modules;
        for (int i = 0; i < moduleNames.length; i++) {
            if (logger.isDebugEnabled())
                logger.debug("Unloading revisions of module " + moduleNames[i] + ".");

            moduleType = this.getHotBeanModuleType(moduleNames[i]);
            if (moduleType != null) {
                modules = moduleType.getModules();
                for (int j = 0; j < modules.length; j++) {
                    if (logger.isDebugEnabled())
                        logger.debug("Checking" + modules[i] + ".");

                    if (modules[j].isActive() || modules[j].isInactive()) {
                        if (logger.isDebugEnabled())
                            logger.debug("Unloading " + modules[j] + ".");
                        modules[j].unload();
                    }
                    this.unregisterHotBeanModule(modules[j]);
                }
            }
        }
    }
}