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

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

Introduction

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

Prototype

void info(Object message, Throwable t);

Source Link

Document

Logs an error with info log level.

Usage

From source file:io.netty.logging.CommonsLoggerTest.java

@Test
public void testInfoWithException() {
    Log mock = createStrictMock(Log.class);

    mock.info("a", e);
    replay(mock);/*w  w  w. j  a v a2s .  c  o  m*/

    InternalLogger logger = new CommonsLogger(mock, "foo");
    logger.info("a", e);
    verify(mock);
}

From source file:fr.gouv.vitam.utils.logging.CommonsLoggerTest.java

@Test
public void testInfoWithException() {
    final Log mock = createStrictMock(Log.class);

    mock.info("a", e);
    replay(mock);//from ww w . j  av a2  s  .c  o m

    final VitamLogger logger = new CommonsLogger(mock, "foo");
    logger.info("a", e);
    verify(mock);
}

From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the message, along with the given <code>throwable</code>, at the info level. If
 * {@link Logger#getDumpStackTraces() stack traces are not to be dumped}, the logged message will be appended
 * with the throwable's <code>Throwable.toString()</code> contents.
 *
 * @param log       where to log the message
 * @param key       the resource key that is associated with the message
 * @param msg       the message to log/*from   w w w  .j a va  2 s .c  om*/
 * @param throwable the throwable associated with the message
 */
private static void logInfoWithThrowable(Log log, String key, Msg msg, Throwable throwable) {
    if (Logger.getDumpStackTraces()) {
        log.info(((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg), throwable);
    } else {
        log.info(((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg) + ". Cause: "
                + throwable.toString());
    }
}

From source file:ductive.log.JDKToCommonsHandler.java

@Override
public void publish(LogRecord record) {
    String name = record.getLoggerName();

    Log log = logs.get(name);
    if (log == null)
        logs.put(name, log = LogFactory.getLog(name));

    String message = record.getMessage();
    Throwable ex = record.getThrown();
    Level level = record.getLevel();

    if (Level.SEVERE == level)
        log.error(message, ex);/*from w ww .j  av  a 2  s. c  o m*/
    else if (Level.WARNING == level)
        log.warn(message, ex);
    else if (Level.INFO == level)
        log.info(message, ex);
    else if (Level.CONFIG == level)
        log.debug(message, ex);
    else
        log.trace(message, ex);
}

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

@Override
public void onCommandFinished(final ICommand command, IStatus status) {
    /*/*  w w w. j av a  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:com.amazon.carbonado.repo.replicated.ReplicatedRepository.java

private <S extends Storable> boolean deleteCorruptEntry(ReplicationTrigger<S> replicationTrigger,
        S replicaWithKeyOnly, CorruptEncodingException e) throws RepositoryException {
    if (replicaWithKeyOnly == null) {
        return false;
    }//from   w  ww  .ja  va 2 s. c o m

    final Log log = LogFactory.getLog(ReplicatedRepository.class);

    // Delete corrupt replica entry.
    try {
        replicationTrigger.deleteReplica(replicaWithKeyOnly);
        log.info("Deleted corrupt replica entry: " + replicaWithKeyOnly.toStringKeyOnly(), e);
        return true;
    } catch (PersistException e2) {
        log.warn("Unable to delete corrupt replica entry: " + replicaWithKeyOnly.toStringKeyOnly(), e2);
        return false;
    }
}

From source file:com.ayovel.nian.exception.XLog.java

private void log(Level level, int loggerMask, String msgTemplate, Object... params) {
    loggerMask |= STD;/*from w w w .  j  a  v a2  s .  com*/
    if (isEnabled(level, loggerMask)) {
        String prefix = getMsgPrefix() != null ? getMsgPrefix() : Info.get().getPrefix();
        prefix = (prefix != null && prefix.length() > 0) ? prefix + " " : "";

        String msg = prefix + format(msgTemplate, params);
        Throwable throwable = getCause(params);

        for (int i = 0; i < LOGGER_MASKS.length; i++) {
            if (isEnabled(level, loggerMask & LOGGER_MASKS[i])) {
                Log log = loggers[i];
                switch (level) {
                case FATAL:
                    log.fatal(msg, throwable);
                    break;
                case ERROR:
                    log.error(msg, throwable);
                    break;
                case INFO:
                    log.info(msg, throwable);
                    break;
                case WARN:
                    log.warn(msg, throwable);
                    break;
                case DEBUG:
                    log.debug(msg, throwable);
                    break;
                case TRACE:
                    log.trace(msg, throwable);
                    break;
                }
            }
        }
    }
}

From source file:net.sf.jabb.util.ex.LoggedException.java

/**
 * Create a new instance, and at the same time, ensure the original exception is logged.
 * //from w w  w.  j a v  a  2 s . co m
 * @param log      the log utility
 * @param level      level of the log
 * @param message   description
 * @param cause      the original exception. If it is of type LoggedException, 
 *                then the newly created instance is a clone of itself.
 */
public LoggedException(Log log, int level, String message, Throwable cause) {
    super(cause instanceof LoggedException ? cause.getMessage() : message,
            cause instanceof LoggedException ? cause.getCause() : cause);
    if (!(cause instanceof LoggedException)) {
        switch (level) {
        case TRACE:
            if (log.isTraceEnabled()) {
                log.trace(message, cause);
            }
            break;
        case DEBUG:
            if (log.isDebugEnabled()) {
                log.debug(message, cause);
            }
            break;
        case WARN:
            if (log.isWarnEnabled()) {
                log.warn(message, cause);
            }
            break;
        case FATAL:
            log.fatal(message, cause);
            break;
        case INFO:
            log.info(message, cause);
            break;
        default:
            log.error(message, cause);
        }
    }
}

From source file:com.amazon.carbonado.repo.replicated.ReplicatedRepository.java

@SuppressWarnings("unchecked")
private <S extends Storable> void resync(ReplicationTrigger<S> replicationTrigger, Storage<S> replicaStorage,
        Query<S> replicaQuery, Storage<S> masterStorage, Query<S> masterQuery,
        ResyncCapability.Listener<? super S> listener, Throttle throttle, double desiredSpeed,
        Comparator comparator, Transaction replicaTxn) throws RepositoryException {
    final Log log = LogFactory.getLog(ReplicatedRepository.class);

    Cursor<S> replicaCursor = null;
    Cursor<S> masterCursor = null;

    try {// ww  w .java  2s .  co m
        while (replicaCursor == null) {
            try {
                replicaCursor = replicaQuery.fetch();
            } catch (CorruptEncodingException e) {
                S replicaWithKeyOnly = recoverReplicaKey(replicaStorage, e);
                if (!deleteCorruptEntry(replicationTrigger, replicaWithKeyOnly, e)) {
                    // Cannot delete it, so just give up.
                    throw e;
                }
            }
        }

        masterCursor = masterQuery.fetch();

        S lastReplicaEntry = null;
        S replicaEntry = null;
        S masterEntry = null;

        int count = 0, txnCount = 0;
        while (true) {
            if (throttle != null) {
                try {
                    // 100 millisecond clock precision
                    throttle.throttle(desiredSpeed, 100);
                } catch (InterruptedException e) {
                    throw new FetchInterruptedException(e);
                }
            }

            if (replicaEntry == null && replicaCursor != null) {
                int skippedCount = 0;
                while (replicaCursor.hasNext()) {
                    try {
                        replicaEntry = replicaCursor.next();
                        if (listener != null) {
                            listener.afterLoad(replicaEntry);
                        }
                        if (skippedCount > 0) {
                            if (skippedCount == 1) {
                                log.warn("Skipped corrupt replica entry before this one: " + replicaEntry);
                            } else {
                                log.warn("Skipped " + skippedCount
                                        + " corrupt replica entries before this one: " + replicaEntry);
                            }
                        }
                        break;
                    } catch (CorruptEncodingException e) {
                        // Exception forces cursor to close. Close again to be sure.
                        replicaCursor.close();
                        replicaCursor = null;

                        S replicaWithKeyOnly = recoverReplicaKey(replicaStorage, e);

                        boolean deleted = deleteCorruptEntry(replicationTrigger, replicaWithKeyOnly, e);

                        // Re-open (if we can)
                        if (lastReplicaEntry == null) {
                            break;
                        }
                        replicaCursor = replicaQuery.fetchAfter(lastReplicaEntry);

                        if (deleted) {
                            // Skip if it cannot be deleted.
                            try {
                                skippedCount = replicaCursor.skipNext(++skippedCount);
                                log.info("Skipped corrupt replica entry", e);
                                if (replicaWithKeyOnly != null) {
                                    // Try to update entry which could not be deleted.
                                    replicaEntry = replicaWithKeyOnly;
                                    if (listener != null) {
                                        listener.afterLoad(replicaEntry);
                                    }
                                    break;
                                }
                            } catch (FetchException e2) {
                                log.error("Unable to skip past corrupt replica entry", e2);
                                throw e;
                            }
                        }
                    }
                }
            }

            if (count++ >= RESYNC_WATERMARK || txnCount >= RESYNC_BATCH_SIZE) {
                replicaTxn.commit();
                if (replicaCursor != null) {
                    // Cursor should auto-close after txn commit, but force
                    // a close anyhow. Cursor is re-opened when it is
                    // allowed to advance.
                    replicaCursor.close();
                    replicaCursor = null;
                }
                count = 0;
                txnCount = 0;
            }

            if (masterEntry == null && masterCursor.hasNext()) {
                masterEntry = masterCursor.next();
            }

            Runnable resyncTask = null;

            // Comparator should treat null as high.
            int compare = comparator.compare(replicaEntry, masterEntry);

            if (compare < 0) {
                // Bogus record exists only in replica so delete it.
                resyncTask = prepareResyncTask(replicationTrigger, listener, replicaEntry, null);
                // Allow replica to advance.
                if (replicaCursor == null) {
                    replicaCursor = replicaQuery.fetchAfter(replicaEntry);
                }
                lastReplicaEntry = replicaEntry;
                replicaEntry = null;
            } else if (compare > 0) {
                // Replica cursor is missing an entry so copy it.
                resyncTask = prepareResyncTask(replicationTrigger, listener, null, masterEntry);
                // Allow master to advance.
                masterEntry = null;
            } else {
                // If compare is zero, replicaEntry and masterEntry are
                // either both null or both non-null.

                if (replicaEntry == null && masterEntry == null) {
                    // Both cursors exhausted -- resync is complete.
                    break;
                }

                // Both replicaEntry and masterEntry are non-null.
                if (!replicaEntry.equalProperties(masterEntry)) {
                    // Replica is stale.
                    resyncTask = prepareResyncTask(replicationTrigger, listener, replicaEntry, masterEntry);
                }

                // Entries are synchronized so allow both cursors to advance.
                if (replicaCursor == null) {
                    replicaCursor = replicaQuery.fetchAfter(replicaEntry);
                }
                lastReplicaEntry = replicaEntry;
                replicaEntry = null;
                masterEntry = null;
            }

            if (resyncTask != null) {
                txnCount++;
                resyncTask.run();
            }
        }
    } finally {
        try {
            if (masterCursor != null) {
                masterCursor.close();
            }
        } finally {
            if (replicaCursor != null) {
                replicaCursor.close();
            }
        }
    }
}

From source file:org.acmsl.queryj.api.AbstractTemplate.java

/**
 * Retrieves the placeholder chain provider.
 * @param context the context./*from   w  ww .  j  ava  2  s.c o m*/
 * @param placeholderPackage the placeholder package.
 * @return the {@link org.acmsl.queryj.tools.PlaceholderChainProvider} class.
 * @throws QueryJBuildException if the factory class is invalid.
 */
@Nullable
@SuppressWarnings("unchecked")
protected Class<FillTemplateChainFactory<C>> retrieveFillTemplateChainFactoryClass(@NotNull final C context,
        @NotNull final String placeholderPackage) throws QueryJBuildException {
    @Nullable
    Class<FillTemplateChainFactory<C>> result = null;

    @NotNull
    final String contextName = context.getClass().getSimpleName().replaceAll("^TemplateDef", "");

    @NotNull
    final String baseName = buildFillTemplateChainFactoryClass(contextName, placeholderPackage);

    try {
        result = (Class<FillTemplateChainFactory<C>>) Class.forName(baseName);
    } catch (@NotNull final ClassNotFoundException classNotFound) {
        @Nullable
        final Log t_Log = UniqueLogFactory.getLog(AbstractQueryJTemplate.class);

        if (t_Log != null) {
            t_Log.info("Template context " + contextName + " not supported", classNotFound);
        }
    }

    return result;
}