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:org.jkcsoft.java.util.OsHelper.java

public static boolean isExecutable(File file, Log log) throws Exception {
    boolean is = true;

    if (isLinux()) {
        // e.g., /usr/bin/test -x /home/coles/build/build-tsess.sh && echo yes || echo no
        try {//from   www  .j  av  a2  s.  co  m

            Runtime rt = Runtime.getRuntime();
            String stTest = "/usr/bin/test -x " + file.getAbsolutePath() + " && echo yes || echo no";
            log.debug("Command=" + stTest);

            Process p = rt.exec(stTest);

            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

            BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

            String stLine = null;

            // read any errors from the attempted command
            log.info("Here is the standard error of the command (if any):");
            while ((stLine = stdError.readLine()) != null) {
                log.warn(stLine);
            }

            // read the output from the command
            StringBuilder sbResponse = new StringBuilder();
            while ((stLine = stdInput.readLine()) != null) {
                sbResponse.append(stLine);
            }

            is = "yes".equalsIgnoreCase(sbResponse.toString());

        } catch (IOException e) {
            log.error("In isExecutable()", e);
            throw e;
        }
    } else {
        log.info("Not Linux -- assume executable");
    }

    return is;
}

From source file:org.kuali.kra.logging.BufferedLogger.java

/**
 * Wraps {@link Log#warn(String)}/* w  ww  . ja va2  s . c  o  m*/
 * 
 * @param pattern to format against
 * @param objs an array of objects used as parameters to the <code>pattern</code>
 */
public static final void warn(Object... objs) {
    Log log = getLogger();
    if (log.isWarnEnabled()) {
        log.warn(getMessage(objs));
    }
}

From source file:org.kuali.rice.krad.datadictionary.validator.ValidationController.java

/**
 * Writes the results of the validation to an output file
 *
 * @param log - The Log4j logger the output is sent to
 * @param validator - The filled validator
 * @param passed - Whether the validation passed or not
 *///w  w  w.j a v  a  2s.  co m
protected void writeToLog(Log log, Validator validator, boolean passed) {
    log.info("Passed: " + passed);
    if (displayErrors) {
        log.info("Number of Errors: " + validator.getNumberOfErrors());
    }
    if (displayWarnings) {
        log.info("Number of Warnings: " + validator.getNumberOfWarnings());
    }

    if (displayErrorMessages) {
        for (int i = 0; i < validator.getErrorReportSize(); i++) {
            if (validator.getErrorReport(i).getErrorStatus() == ErrorReport.ERROR) {
                if (displayXmlPages) {
                    log.error(validator.getErrorReport(i).errorMessage()
                            + validator.getErrorReport(i).errorPageList());
                } else {
                    log.error(validator.getErrorReport(i).errorMessage());
                }

            } else {
                if (displayWarningMessages) {
                    if (displayXmlPages) {
                        log.warn(validator.getErrorReport(i).errorMessage()
                                + validator.getErrorReport(i).errorPageList());
                    } else {
                        log.warn(validator.getErrorReport(i).errorMessage());
                    }
                }
            }

        }
    }
}

From source file:org.lockss.util.FuncCommonsLoggingLogger.java

public void testLog() {
    String msg = "test message 42";
    String logName = "TestLog";
    MockLogTarget target = new MockLogTarget();
    Log log = LogFactory.getLog(logName);
    Logger lockssLog = Logger.getLogger(logName);
    Logger.setTarget(target);//from w w w  .  j a v  a  2  s . co  m
    // disable thread id, makes message order dependent on debug level
    lockssLog.setIdThread(false);
    assertEmpty(target.getMessages());
    log.warn(msg);
    List m = target.getMessages();
    System.out.println("loglog: " + m);
    assertEquals(1, m.size());
    String m0 = (String) m.get(0);
    assertNotEquals(-1, m0.indexOf(msg));
}

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//from   w w  w . ja v a  2 s .co 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.nuxeo.ecm.automation.core.operations.LogOperation.java

@OperationMethod
public void run() {
    if (category == null) {
        category = "org.nuxeo.ecm.automation.logger";
    }//from  w  w w .  j a  v  a  2s  .com

    Log log = LogFactory.getLog(category);

    if ("debug".equals(level)) {
        log.debug(message);
        return;
    }

    if ("warn".equals(level)) {
        log.warn(message);
        return;
    }

    if ("error".equals(level)) {
        log.error(message);
        return;
    }
    // in any other case, use info log level
    log.info(message);

}

From source file:org.onecmdb.core.internal.model.InstanceTypeSelector.java

public Set<IType> getSet() {
    Set<IType> types = new HashSet<IType>();

    /* the attribute's value type itself first */
    types.add(this.attr.getValueType());

    /* then all offsprings */
    IType type = this.attr.getValueType();
    if (type == null) {
        Log log = OneCmdb.getLogger(InstanceTypeSelector.class);
        log.warn("No type found for attribute '" + attr.getId() + ":" + attr.getAlias() + "'");

    } else {//from  w w  w. j  a  v  a 2  s  . c om

        types.addAll(type.getAllOffspringTypes());
    }

    return types;
}

From source file:org.opencms.pdftools.CmsXRLogAdapter.java

/**
 * Sends a log message to the commons-logging interface.<p>
 *
 * @param level the log level//from ww w  .  ja v  a 2s  . c  o m
 * @param message the message
 * @param log the commons logging log object
 * @param e a throwable or null
 */
private void sendMessageToLogger(Level level, String message, Log log, Throwable e) {

    if (e == null) {
        if (level == Level.SEVERE) {
            log.error(message);
        } else if (level == Level.WARNING) {
            log.warn(message);
        } else if (level == Level.INFO) {
            log.info(message);
        } else if (level == Level.CONFIG) {
            log.info(message);
        } else if ((level == Level.FINE) || (level == Level.FINER) || (level == Level.FINEST)) {
            log.debug(message);
        } else {
            log.info(message);
        }
    } else {
        if (level == Level.SEVERE) {
            log.error(message, e);
        } else if (level == Level.WARNING) {
            log.warn(message, e);
        } else if (level == Level.INFO) {
            log.info(message, e);
        } else if (level == Level.CONFIG) {
            log.info(message, e);
        } else if ((level == Level.FINE) || (level == Level.FINER) || (level == Level.FINEST)) {
            log.debug(message, e);
        } else {
            log.info(message, e);
        }
    }
}

From source file:org.opendatakit.common.persistence.engine.gae.QueryImpl.java

final static synchronized void updateCostLoggingThreshold(DatastoreImpl datastore) {
    Log logger = LogFactory.getLog(QueryImpl.class);

    long currentTime = System.currentTimeMillis();
    if (milliLastCheck + ACTIVE_COST_LOGGING_CHECK_INTERVAL < currentTime) {

        milliLastCheck = currentTime;// update early in case an exception is
                                     // thrown...
        try {/*from   w  ww  .ja va 2 s.co m*/
            com.google.appengine.api.datastore.Query query = new Query("_COST_LOGGING_");
            PreparedQuery pq = datastore.getDatastoreService().prepare(query);
            logger.debug("costLogging fetch.");
            List<com.google.appengine.api.datastore.Entity> eList = pq
                    .asList(FetchOptions.Builder.withDefaults());
            datastore.recordQueryUsage("_COST_LOGGING_", eList.size());
            if (eList.isEmpty()) {
                costLoggingMinimumMegacyclesThreshold = 10 * 1200; // 10 seconds...
                logger.warn("writing 10-second cost logging threshold record");
                com.google.appengine.api.datastore.Entity e = new com.google.appengine.api.datastore.Entity(
                        "_COST_LOGGING_", "T" + WebUtils.iso8601Date(new Date()));
                e.setProperty("COST_LOGGING_MEGACYCLE_THRESHOLD", 10 * 1200); // 10
                                                                              // seconds...
                e.setProperty("LAST_UPDATE_DATE", new Date());
                datastore.getDatastoreService().put(e);
            } else {
                Long newValue = null;
                for (com.google.appengine.api.datastore.Entity e : eList) {
                    Object o = e.getProperty("COST_LOGGING_MEGACYCLE_THRESHOLD");
                    if (o != null) {
                        if (o instanceof Long) {
                            Long l = (Long) o;
                            if (newValue == null || newValue.compareTo(l) > 0) {
                                newValue = l;
                            } else {
                                logger.warn("deleting superceded logging threshold record");
                                datastore.getDatastoreService().delete(e.getKey());
                            }
                        } else if (o instanceof Integer) {
                            Integer i = (Integer) o;
                            Long l = Long.valueOf(i);
                            if (newValue == null || newValue.compareTo(l) > 0) {
                                newValue = l;
                            } else {
                                logger.warn("deleting superceded logging threshold record");
                                datastore.getDatastoreService().delete(e.getKey());
                            }
                        } else if (o instanceof String) {
                            String s = (String) o;
                            try {
                                Long l = Long.parseLong(s);
                                if (newValue == null || newValue.compareTo(l) > 0) {
                                    newValue = l;
                                } else {
                                    logger.warn("deleting superceded logging threshold record");
                                    datastore.getDatastoreService().delete(e.getKey());
                                }
                            } catch (NumberFormatException ex) {
                                logger.warn("deleting superceded logging threshold record");
                                datastore.getDatastoreService().delete(e.getKey());
                            }
                        } else {
                            logger.warn("deleting superceded logging threshold record");
                            datastore.getDatastoreService().delete(e.getKey());
                        }
                    }
                }
                if (newValue == null) {
                    logger.warn("resetting cost logging to 10 second (12000 megacycle) threshold");
                    costLoggingMinimumMegacyclesThreshold = 10 * 1200; // 10 seconds...
                } else if (costLoggingMinimumMegacyclesThreshold != newValue.longValue()) {
                    logger.warn("changing cost logging to " + newValue + " megacycle threshold");
                    costLoggingMinimumMegacyclesThreshold = newValue;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("exception while updating cost logging threshold: " + e.getMessage());
        }
    }
}

From source file:org.openmrs.web.Listener.java

/**
 * Convenience method to empty out the dwr-modules.xml file to fix any errors that might have
 * occurred in it when loading or unloading modules.
 *
 * @param servletContext//  w  w  w.j ava 2 s . com
 */
private void clearDWRFile(ServletContext servletContext) {
    Log log = LogFactory.getLog(Listener.class);

    String realPath = servletContext.getRealPath("");
    String absPath = realPath + "/WEB-INF/dwr-modules.xml";
    File dwrFile = new File(absPath.replace("/", File.separator));
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        db.setEntityResolver(new EntityResolver() {

            public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException {
                // When asked to resolve external entities (such as a DTD) we return an InputSource
                // with no data at the end, causing the parser to ignore the DTD.
                return new InputSource(new StringReader(""));
            }
        });
        Document doc = db.parse(dwrFile);
        Element elem = doc.getDocumentElement();
        elem.setTextContent("");
        OpenmrsUtil.saveDocument(doc, dwrFile);
    } catch (Exception e) {
        // got here because the dwr-modules.xml file is empty for some reason.  This might
        // happen because the servlet container (i.e. tomcat) crashes when first loading this file
        log.debug("Error clearing dwr-modules.xml", e);
        dwrFile.delete();
        FileWriter writer = null;
        try {
            writer = new FileWriter(dwrFile);
            writer.write(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE dwr PUBLIC \"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN\" \"http://directwebremoting.org/schema/dwr20.dtd\">\n<dwr></dwr>");
        } catch (IOException io) {
            log.error("Unable to clear out the " + dwrFile.getAbsolutePath()
                    + " file.  Please redeploy the openmrs war file", io);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException io) {
                    log.warn("Couldn't close Writer: " + io);
                }
            }
        }
    }
}