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

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

Introduction

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

Prototype

void warn(Object message);

Source Link

Document

Logs a message with warn log level.

Usage

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

/**
 * Process a fetched search result (collect ids and cache records)
 * /*from  w w w  .  ja  v a  2s.  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:net.sf.nmedit.nordmodular.NMSynthDeviceContext.java

public void openOrSelectPatch(Slot slot) {
    NmSlot nmslot = (NmSlot) slot;/*from ww  w .j a  va2s . c om*/

    NMPatch patch = nmslot.getPatch();

    if (patch != null) {
        // find out if patch is open

        DefaultDocumentManager dm = Nomad.sharedInstance().getDocumentManager();

        for (Document d : dm.getDocuments()) {
            if (d instanceof PatchDocument) {
                PatchDocument pd = (PatchDocument) d;
                if (pd.getPatch() == patch) {
                    // found -> select

                    dm.setSelection(d);

                    return;
                }
            }
        }

        // not found -> create document

        try {
            final PatchDocument pd = NmFileService.createPatchDoc(patch);

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    DocumentManager dm = Nomad.sharedInstance().getDocumentManager();
                    dm.add(pd);
                    dm.setSelection(pd);

                }
            });

        } catch (Exception e) {

            Log log = LogFactory.getLog(getClass());
            if (log.isWarnEnabled()) {
                log.warn(e);
            }

            ExceptionDialog.showErrorDialog(Nomad.sharedInstance().getWindow().getRootPane(),

                    e.getMessage(), "could not open patch", e);

            return;
        }

        return;
    }

    try {
        slot.createRequestPatchWorker().requestPatch();
    } catch (SynthException e1) {
        e1.printStackTrace();
    }
}

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./*  www  . ja v a2  s . com*/
 *
 * 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.acciente.induction.template.FreemarkerTemplatingEngine.java

public FreemarkerTemplatingEngine(Config.Templating oConfig, ClassLoader oClassLoader,
        ServletConfig oServletConfig) throws IOException, ClassNotFoundException {
    Log oLog;

    oLog = LogFactory.getLog(FreemarkerTemplatingEngine.class);

    _oConfiguration = new Configuration();

    // set up the template loading path
    List oTemplateLoaderList = new ArrayList(oConfig.getTemplatePath().getList().size());

    for (Iterator oIter = oConfig.getTemplatePath().getList().iterator(); oIter.hasNext();) {
        Object oLoaderPathItem = oIter.next();

        if (oLoaderPathItem instanceof Config.Templating.TemplatePath.Dir) {
            Config.Templating.TemplatePath.Dir oDir = (Config.Templating.TemplatePath.Dir) oLoaderPathItem;

            if (!oDir.getDir().exists()) {
                oLog.warn("freemarker > template load path > ignoring missing directory > " + oDir.getDir());
            } else {
                oLog.info("freemarker > template load path > adding directory > " + oDir.getDir());

                oTemplateLoaderList.add(new FileTemplateLoader(oDir.getDir()));
            }/* w  w w.j av  a  2s  .c o  m*/
        } else if (oLoaderPathItem instanceof Config.Templating.TemplatePath.LoaderClass) {
            Config.Templating.TemplatePath.LoaderClass oLoaderClass = (Config.Templating.TemplatePath.LoaderClass) oLoaderPathItem;

            Class oClass = Class.forName(oLoaderClass.getLoaderClassName());

            oLog.info("freemarker > template load path > adding class > " + oLoaderClass.getLoaderClassName()
                    + ", prefix: " + oLoaderClass.getPath());

            oTemplateLoaderList.add(new ClassTemplateLoader(oClass, oLoaderClass.getPath()));
        } else if (oLoaderPathItem instanceof Config.Templating.TemplatePath.WebappPath) {
            Config.Templating.TemplatePath.WebappPath oWebappPath = (Config.Templating.TemplatePath.WebappPath) oLoaderPathItem;

            oLog.info("freemarker > template load path > adding webapp path > " + oWebappPath.getPath());

            oTemplateLoaderList
                    .add(new WebappTemplateLoader(oServletConfig.getServletContext(), oWebappPath.getPath()));
        } else {
            throw new IllegalArgumentException(
                    "Unexpected template path type in configuration: " + oLoaderPathItem.getClass());
        }
    }

    TemplateLoader[] oTemplateLoaderArray = new TemplateLoader[oTemplateLoaderList.size()];
    oTemplateLoaderList.toArray(oTemplateLoaderArray);
    _oConfiguration.setTemplateLoader(new MultiTemplateLoader(oTemplateLoaderArray));

    // next set the object wrapper handler
    DefaultObjectWrapper oDefaultObjectWrapper = new DefaultObjectWrapper();

    // should publics fields in views be available in the templates
    oDefaultObjectWrapper.setExposeFields(oConfig.isExposePublicFields());

    oLog.info("freemarker > expose public fields > " + oConfig.isExposePublicFields());

    _oConfiguration.setObjectWrapper(oDefaultObjectWrapper);

    if (oConfig.getLocale() != null) {
        _oConfiguration.setLocale(oConfig.getLocale());

        oLog.info("freemarker > using configured locale > " + oConfig.getLocale());
    } else {
        oLog.warn("freemarker > no locale configured, using default > " + _oConfiguration.getLocale());
    }
}

From source file:com.healthmarketscience.rmiio.RemoteRetry.java

/**
 * Implementation of the actual retry logic. Calls the call() method of the
 * given Caller, returning results. All Throwables will be caught and
 * shouldRetry() will be queried to see if the call should be reattempted.
 * Iff shouldRetry() returns <code>true</code>, backoff() is called in order
 * to allow the other end of the connection to have a breather and then the
 * call() is reattempted (and the cycle repeats). Otherwise, the original
 * Throwable is thrown to the caller./*from   www.j a v a 2  s . c o  m*/
 * 
 * @param caller
 *           implementation of the actual remote method call
 */
protected final <RetType> RetType callImpl(Caller<RetType> caller, Log log) throws Throwable {
    int numTries = 0;
    do {
        try {
            // attempt actual remote call
            return caller.call();
        } catch (Throwable e) {

            // keep track of number of retries
            ++numTries;

            // determine if caller wants to retry
            if (!shouldRetry(e, numTries)) {
                // guess not...
                log.warn("Retry for caller " + caller + " giving up!");
                throw e;
            }

            if (log.isDebugEnabled()) {
                log.debug("Caller " + caller + " got exception, retrying", e);
            }

            // wait for a bit before retrying
            backOff(numTries, log);
        }
    } while (true);
}

From source file:dk.netarkivet.common.utils.batch.GoodPostProcessingJob.java

@Override
public boolean postProcess(InputStream input, OutputStream output) {
    Log log = LogFactory.getLog(this.getClass());
    try {/*from w ww.ja  v  a 2 s.c o  m*/
        // sort the input stream.
        List<String> filenames = new ArrayList<String>();

        log.info("Reading all the filenames.");
        // read all the filenames.
        BufferedReader br = new BufferedReader(new InputStreamReader(input));
        String line;
        while ((line = br.readLine()) != null) {
            filenames.add(line);
        }

        log.info("Sorting the filenames");
        // sort and print to output.
        Collections.sort(filenames);
        for (String file : filenames) {
            output.write(file.getBytes());
            output.write("\n".getBytes());
        }

        return true;
    } catch (Exception e) {
        log.warn(e.getMessage());
        return false;
    }
}

From source file:cn.scala.es.HeartBeat.java

HeartBeat(final Progressable progressable, Configuration cfg, TimeValue lead, final Log log) {
    Assert.notNull(progressable, "a valid progressable is required to report status to Hadoop");
    TimeValue tv = HadoopCfgUtils.getTaskTimeout(cfg);

    Assert.isTrue(tv.getSeconds() <= 0 || tv.getSeconds() > lead.getSeconds(),
            "Hadoop timeout is shorter than the heartbeat");

    this.progressable = progressable;
    long cfgMillis = (tv.getMillis() > 0 ? tv.getMillis() : 0);
    // the task is simple hence the delay = timeout - lead, that is when to start the notification right before the timeout
    this.delay = new TimeValue(Math.abs(cfgMillis - lead.getMillis()), TimeUnit.MILLISECONDS);
    this.log = log;

    String taskId;//from  w w  w  .java2  s .  c  om
    TaskID taskID = HadoopCfgUtils.getTaskID(cfg);

    if (taskID == null) {
        log.warn("Cannot determine task id...");
        taskId = "<unknown>";
        if (log.isTraceEnabled()) {
            log.trace("Current configuration is " + HadoopCfgUtils.asProperties(cfg));
        }
    } else {
        taskId = "" + taskID;
    }

    id = taskId;
}

From source file:javadz.beanutils.MethodUtils.java

/**
 * Try to make the method accessible/*ww w  . j a  v  a  2  s. c om*/
 * @param method The source arguments
 */
private static void setMethodAccessible(Method method) {
    try {
        //
        // XXX Default access superclass workaround
        //
        // When a public class has a default access superclass
        // with public methods, these methods are accessible.
        // Calling them from compiled code works fine.
        //
        // Unfortunately, using reflection to invoke these methods
        // seems to (wrongly) to prevent access even when the method
        // modifer is public.
        //
        // The following workaround solves the problem but will only
        // work from sufficiently privilages code. 
        //
        // Better workarounds would be greatfully accepted.
        //
        if (!method.isAccessible()) {
            method.setAccessible(true);
        }

    } catch (SecurityException se) {
        // log but continue just in case the method.invoke works anyway
        Log log = LogFactory.getLog(MethodUtils.class);
        if (!loggedAccessibleWarning) {
            boolean vulnerableJVM = false;
            try {
                String specVersion = System.getProperty("java.specification.version");
                if (specVersion.charAt(0) == '1'
                        && (specVersion.charAt(2) == '0' || specVersion.charAt(2) == '1'
                                || specVersion.charAt(2) == '2' || specVersion.charAt(2) == '3')) {

                    vulnerableJVM = true;
                }
            } catch (SecurityException e) {
                // don't know - so display warning
                vulnerableJVM = true;
            }
            if (vulnerableJVM) {
                log.warn("Current Security Manager restricts use of workarounds for reflection bugs "
                        + " in pre-1.4 JVMs.");
            }
            loggedAccessibleWarning = true;
        }
        log.debug("Cannot setAccessible on method. Therefore cannot use jvm access bug workaround.", se);
    }
}

From source file:net.fenyo.mail4hotspot.service.AdvancedServicesImpl.java

@Override
public void testLog() {
    final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(getClass());

    log.trace("testlog: TRACE");
    log.fatal("testlog: FATAL");
    log.error("testlog: ERROR");
    log.info("testlog: INFO");
    log.debug("testlog: DEBUG");
    log.warn("testlog: WARN");
}

From source file:com.acc.web.manager.LogManager.java

private void log(Object logTypeObject, Object prefixObject, Object informationObject, LogType logType) {
    if (!AppLibConstant.isUseLog()) {
        return;/*ww  w .  j  a v a 2s .c o m*/
    }
    Log log = logType == LogType.SYSTEMOUT || logType == LogType.FILE ? null : this.getLogger(logTypeObject);
    String logString = this.getLogString(prefixObject, informationObject);
    switch (logType) {
    case SYSTEMOUT:
        super.systemOut(logString);
        break;
    case FILE:
        super.fileOut(logString);
        break;
    case INFO:
        log.info(logString);
        break;
    case WARN:
        log.warn(logString);
        break;
    case DEBUG:
        log.debug(logString);
        break;
    case ERROR:
        log.error(logString);
        break;
    case FATAL:
        log.fatal(logString);
        break;
    }
}