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.openmrs.web.Listener.java

/**
 * Copy the customization scripts over into the webapp
 *
 * @param servletContext//from  w ww . ja  v  a2s  .c o m
 */
private void copyCustomizationIntoWebapp(ServletContext servletContext, Properties props) {
    Log log = LogFactory.getLog(Listener.class);

    String realPath = servletContext.getRealPath("");
    // TODO centralize map to WebConstants?
    Map<String, String> custom = new HashMap<String, String>();
    custom.put("custom.template.dir", "/WEB-INF/template");
    custom.put("custom.index.jsp.file", "/WEB-INF/view/index.jsp");
    custom.put("custom.login.jsp.file", "/WEB-INF/view/login.jsp");
    custom.put("custom.patientDashboardForm.jsp.file", "/WEB-INF/view/patientDashboardForm.jsp");
    custom.put("custom.images.dir", "/images");
    custom.put("custom.style.css.file", "/style.css");
    custom.put("custom.messages", "/WEB-INF/custom_messages.properties");
    custom.put("custom.messages_fr", "/WEB-INF/custom_messages_fr.properties");
    custom.put("custom.messages_es", "/WEB-INF/custom_messages_es.properties");
    custom.put("custom.messages_de", "/WEB-INF/custom_messages_de.properties");

    for (Map.Entry<String, String> entry : custom.entrySet()) {
        String prop = entry.getKey();
        String webappPath = entry.getValue();
        String userOverridePath = props.getProperty(prop);
        // if they defined the variable
        if (userOverridePath != null) {
            String absolutePath = realPath + webappPath;
            File file = new File(userOverridePath);

            // if they got the path correct
            // also, if file does not start with a "." (hidden files, like SVN files)
            if (file.exists() && !userOverridePath.startsWith(".")) {
                log.debug("Overriding file: " + absolutePath);
                log.debug("Overriding file with: " + userOverridePath);
                if (file.isDirectory()) {
                    for (File f : file.listFiles()) {
                        userOverridePath = f.getAbsolutePath();
                        if (!f.getName().startsWith(".")) {
                            String tmpAbsolutePath = absolutePath + "/" + f.getName();
                            if (!copyFile(userOverridePath, tmpAbsolutePath)) {
                                log.warn("Unable to copy file in folder defined by runtime property: " + prop);
                                log.warn("Your source directory (or a file in it) '" + userOverridePath
                                        + " cannot be loaded or destination '" + tmpAbsolutePath
                                        + "' cannot be found");
                            }
                        }
                    }
                } else {
                    // file is not a directory
                    if (!copyFile(userOverridePath, absolutePath)) {
                        log.warn("Unable to copy file defined by runtime property: " + prop);
                        log.warn("Your source file '" + userOverridePath + " cannot be loaded or destination '"
                                + absolutePath + "' cannot be found");
                    }
                }
            }
        }

    }
}

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

/**
 * Load the pre-packaged modules from web/WEB-INF/bundledModules. <br>
 * <br>/* w  w  w . j  av  a 2  s .com*/
 * This method assumes that the api startup() and WebModuleUtil.startup() will be called later
 * for modules that loaded here
 *
 * @param servletContext the current servlet context for the webapp
 */
public static void loadBundledModules(ServletContext servletContext) {
    Log log = LogFactory.getLog(Listener.class);

    String path = servletContext.getRealPath("");
    path += File.separator + "WEB-INF" + File.separator + "bundledModules";
    File folder = new File(path);

    if (!folder.exists()) {
        log.warn("Bundled module folder doesn't exist: " + folder.getAbsolutePath());
        return;
    }
    if (!folder.isDirectory()) {
        log.warn("Bundled module folder isn't really a directory: " + folder.getAbsolutePath());
        return;
    }

    // loop over the modules and load the modules that we can
    for (File f : folder.listFiles()) {
        if (!f.getName().startsWith(".")) { // ignore .svn folder and the like
            try {
                Module mod = ModuleFactory.loadModule(f);
                log.debug("Loaded bundled module: " + mod + " successfully");
            } catch (Exception e) {
                log.warn("Error while trying to load bundled module " + f.getName() + "", e);
            }
        }
    }
}

From source file:org.pentaho.platform.engine.services.actions.TestLoggingSessionAwareAction.java

public void setLogger(Log logger) {
    this.logger = logger;
    logger.warn("Test Warning Message");
}

From source file:org.pentaho.reporting.libraries.xmlns.parser.AbstractReadHandlerFactory.java

/**
 * Configures this factory from the given configuration using the specified prefix as filter.
 *
 * @param conf   the configuration./*from w w w .  java 2  s  . c om*/
 * @param prefix the key-prefix.
 * @noinspection ObjectAllocationInLoop as this method configures the factory.
 */
public void configure(final Configuration conf, final String prefix) {
    final HashMap<String, String> knownNamespaces = new HashMap<String, String>();

    final String nsConfPrefix = prefix + "namespace.";
    final Iterator namespaces = conf.findPropertyKeys(nsConfPrefix);
    while (namespaces.hasNext()) {
        final String key = (String) namespaces.next();
        final String nsPrefix = key.substring(nsConfPrefix.length());
        final String nsUri = conf.getConfigProperty(key);
        knownNamespaces.put(nsPrefix, nsUri);
    }

    final Log legacyWarningLog = LogFactory.getLog(getClass());
    boolean warnedLegacyConfig = false;
    final String legacyDefaultNamespace = knownNamespaces.get(conf.getConfigProperty(prefix + "namespace"));
    if (legacyDefaultNamespace != null) {
        if (warnedLegacyConfig == false) {
            legacyWarningLog.warn("Configured configuration-properties based override for global read-hander. "
                    + "Change your code to use proper module-initializers instead. "
                    + "This method of configuring the parser will go away in the next major version.");
            warnedLegacyConfig = true;
        }
        setDefaultNamespace(legacyDefaultNamespace);
    }

    final String globalDefaultKey = prefix + "default";
    final String globalValue = conf.getConfigProperty(globalDefaultKey);
    if (isValidHandler(globalValue)) {
        this.tagData.put(new TagDefinitionKey(null, null), new TagDefinitionValue(globalValue, true));
        if (warnedLegacyConfig == false) {
            legacyWarningLog.warn("Configured configuration-properties based override for global read-hander. "
                    + "Change your code to use proper module-initializers instead. "
                    + "This method of configuring the parser will go away in the next major version.");
            warnedLegacyConfig = true;
        }
    }

    final String nsDefaultPrefix = prefix + "default.";
    final Iterator defaults = conf.findPropertyKeys(nsDefaultPrefix);
    while (defaults.hasNext()) {
        final String key = (String) defaults.next();
        final String nsPrefix = key.substring(nsDefaultPrefix.length());
        final String nsUri = knownNamespaces.get(nsPrefix);
        if (nsUri == null) {
            continue;
        }

        final String tagData = conf.getConfigProperty(key);
        if (tagData == null) {
            continue;
        }
        if (isValidHandler(tagData)) {
            if (warnedLegacyConfig == false) {
                legacyWarningLog
                        .warn("Configured configuration-properties based override for global read-hander. "
                                + "Change your code to use proper module-initializers instead. "
                                + "This method of configuring the parser will go away in the next major version.");
                warnedLegacyConfig = true;
            }
            this.tagData.put(new TagDefinitionKey(nsUri, null), new TagDefinitionValue(tagData, true));
        }
    }

    final String nsTagsPrefix = prefix + "tag.";
    final Iterator tags = conf.findPropertyKeys(nsTagsPrefix);
    while (tags.hasNext()) {
        final String key = (String) tags.next();
        final String tagDef = key.substring(nsTagsPrefix.length());
        final String tagData = conf.getConfigProperty(key);
        if (tagData == null) {
            continue;
        }
        if (isValidHandler(tagData) == false) {
            continue;
        }

        if (warnedLegacyConfig == false) {
            legacyWarningLog.warn("Configured configuration-properties based override for global read-hander. "
                    + "Change your code to use proper module-initializers instead. "
                    + "This method of configuring the parser will go away in the next major version.");
            warnedLegacyConfig = true;
        }

        final int delim = tagDef.indexOf('.');
        if (delim == -1) {
            this.tagData.put(new TagDefinitionKey(null, tagDef), new TagDefinitionValue(tagData, true));
        } else {
            final String nsPrefix = tagDef.substring(0, delim);
            final String nsUri = knownNamespaces.get(nsPrefix);
            if (nsUri == null) {
                continue;
            }

            final String tagName = tagDef.substring(delim + 1);
            this.tagData.put(new TagDefinitionKey(nsUri, tagName), new TagDefinitionValue(tagData, true));
        }
    }
}

From source file:org.picocontainer.gems.monitors.CommonsLoggingComponentMonitor.java

/** {@inheritDoc} **/
public Object noComponentFound(final MutablePicoContainer container, final Object componentKey) {
    Log log = this.log != null ? this.log : LogFactory.getLog(ComponentMonitor.class);
    if (log.isWarnEnabled()) {
        log.warn(ComponentMonitorHelper.format(ComponentMonitorHelper.NO_COMPONENT, componentKey));
    }/*  w ww . j a va  2  s .co m*/
    return delegate.noComponentFound(container, componentKey);
}

From source file:org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil.java

/**
 * Loads a plugin descriptor from the given plugin jar and returns it.
 *
 * This is a static method to provide a convenience method for others to be able to use.
 *
 * @param pluginJarFileUrl URL to a plugin jar file
 * @return the plugin descriptor found in the given plugin jar file
 * @throws PluginContainerException if failed to find or parse a descriptor file in the plugin jar
 *//*from  www .  ja  va2  s.com*/
public static PluginDescriptor loadPluginDescriptorFromUrl(URL pluginJarFileUrl)
        throws PluginContainerException {

    final Log logger = LogFactory.getLog(AgentPluginDescriptorUtil.class);

    if (pluginJarFileUrl == null) {
        throw new PluginContainerException("A valid plugin JAR URL must be supplied.");
    }
    logger.debug("Loading plugin descriptor from plugin jar at [" + pluginJarFileUrl + "]...");

    testPluginJarIsReadable(pluginJarFileUrl);

    JarInputStream jis = null;
    JarEntry descriptorEntry = null;
    ValidationEventCollector validationEventCollector = new ValidationEventCollector();
    try {
        jis = new JarInputStream(pluginJarFileUrl.openStream());
        JarEntry nextEntry = jis.getNextJarEntry();
        while (nextEntry != null && descriptorEntry == null) {
            if (PLUGIN_DESCRIPTOR_PATH.equals(nextEntry.getName())) {
                descriptorEntry = nextEntry;
            } else {
                jis.closeEntry();
                nextEntry = jis.getNextJarEntry();
            }
        }

        if (descriptorEntry == null) {
            throw new Exception("The plugin descriptor does not exist");
        }

        return parsePluginDescriptor(jis, validationEventCollector);
    } catch (Exception e) {
        throw new PluginContainerException(
                "Could not successfully parse the plugin descriptor [" + PLUGIN_DESCRIPTOR_PATH
                        + "] found in plugin jar at [" + pluginJarFileUrl + "].",
                new WrappedRemotingException(e));
    } finally {
        if (jis != null) {
            try {
                jis.close();
            } catch (Exception e) {
                logger.warn("Cannot close jar stream [" + pluginJarFileUrl + "]. Cause: " + e);
            }
        }

        logValidationEvents(pluginJarFileUrl, validationEventCollector, logger);
    }
}

From source file:org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil.java

private static void logValidationEvents(URL pluginJarFileUrl, ValidationEventCollector validationEventCollector,
        Log logger) {
    for (ValidationEvent event : validationEventCollector.getEvents()) {
        // First build the message to be logged. The message will look something like this:
        ////w ww  .  ja v a2 s. c  om
        //   Validation fatal error while parsing [jopr-jboss-as-plugin-4.3.0-SNAPSHOT.jar:META-INF/rhq-plugin.xml]
        //   at line 221, column 94: cvc-minInclusive-valid: Value '20000' is not facet-valid with respect to
        //   minInclusive '30000' for type '#AnonType_defaultIntervalmetric'.
        //
        StringBuilder message = new StringBuilder();
        String severity = null;
        switch (event.getSeverity()) {
        case ValidationEvent.WARNING:
            severity = "warning";
            break;
        case ValidationEvent.ERROR:
            severity = "error";
            break;
        case ValidationEvent.FATAL_ERROR:
            severity = "fatal error";
            break;
        }
        message.append("Validation ").append(severity);
        File pluginJarFile = new File(pluginJarFileUrl.getPath());
        message.append(" while parsing [").append(pluginJarFile.getName()).append(":")
                .append(PLUGIN_DESCRIPTOR_PATH).append("]");
        ValidationEventLocator locator = event.getLocator();
        message.append(" at line ").append(locator.getLineNumber());
        message.append(", column ").append(locator.getColumnNumber());
        message.append(": ").append(event.getMessage());

        // Now write the message to the log at an appropriate level.
        switch (event.getSeverity()) {
        case ValidationEvent.WARNING:
        case ValidationEvent.ERROR:
            logger.warn(message);
            break;
        case ValidationEvent.FATAL_ERROR:
            logger.error(message);
            break;
        }
    }
}

From source file:org.rhq.enterprise.server.xmlschema.ServerPluginDescriptorUtil.java

/**
 * Loads a plugin descriptor from the given plugin jar and returns it. If the given jar does not
 * have a server plugin descriptor, <code>null</code> will be returned, meaning this is not
 * a server plugin jar./*www.  j a v  a 2 s .  c o m*/
 *  
 * @param pluginJarFileUrl URL to a plugin jar file
 * @return the plugin descriptor found in the given plugin jar file, or <code>null</code> if there
 *         is no plugin descriptor in the jar file
 * @throws Exception if failed to parse the descriptor file found in the plugin jar
 */
public static ServerPluginDescriptorType loadPluginDescriptorFromUrl(URL pluginJarFileUrl) throws Exception {

    final Log logger = LogFactory.getLog(ServerPluginDescriptorUtil.class);

    if (pluginJarFileUrl == null) {
        throw new Exception("A valid plugin JAR URL must be supplied.");
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Loading plugin descriptor from plugin jar at [" + pluginJarFileUrl + "]...");
    }

    testPluginJarIsReadable(pluginJarFileUrl);

    JarInputStream jis = null;
    JarEntry descriptorEntry = null;

    try {
        jis = new JarInputStream(pluginJarFileUrl.openStream());
        JarEntry nextEntry = jis.getNextJarEntry();
        while (nextEntry != null && descriptorEntry == null) {
            if (PLUGIN_DESCRIPTOR_PATH.equals(nextEntry.getName())) {
                descriptorEntry = nextEntry;
            } else {
                jis.closeEntry();
                nextEntry = jis.getNextJarEntry();
            }
        }

        ServerPluginDescriptorType pluginDescriptor = null;

        if (descriptorEntry != null) {
            Unmarshaller unmarshaller = null;
            try {
                unmarshaller = getServerPluginDescriptorUnmarshaller();
                Object jaxbElement = unmarshaller.unmarshal(jis);
                pluginDescriptor = ((JAXBElement<? extends ServerPluginDescriptorType>) jaxbElement).getValue();
            } finally {
                if (unmarshaller != null) {
                    ValidationEventCollector validationEventCollector = (ValidationEventCollector) unmarshaller
                            .getEventHandler();
                    logValidationEvents(pluginJarFileUrl, validationEventCollector);
                }
            }
        }

        return pluginDescriptor;

    } catch (Exception e) {
        throw new Exception("Could not successfully parse the plugin descriptor [" + PLUGIN_DESCRIPTOR_PATH
                + "] found in plugin jar at [" + pluginJarFileUrl + "]", e);
    } finally {
        if (jis != null) {
            try {
                jis.close();
            } catch (Exception e) {
                logger.warn("Cannot close jar stream [" + pluginJarFileUrl + "]. Cause: " + e);
            }
        }
    }
}

From source file:org.rhq.plugins.platform.content.RpmPackageDiscoveryDelegate.java

public static Set<ResourcePackageDetails> discoverPackages(PackageType type) throws IOException {
    Log log = LogFactory.getLog(RpmPackageDiscoveryDelegate.class);

    Set<ResourcePackageDetails> packages = new HashSet<ResourcePackageDetails>();

    if (rpmExecutable == null) {
        return packages;
    }//from  w  ww.j a  va  2  s.co  m

    /* Sample output from: rpm -qa
     * xorg-x11-fonts-ethiopic-7.2-3.fc8 bitmap-fonts-0.3-5.1.2.fc7 bluez-utils-cups-3.20-4.fc8
     *
     * In short, it's a list of installed packages.
     */
    ProcessExecution listRpmsProcess = new ProcessExecution(rpmExecutable);
    listRpmsProcess.setArguments(new String[] { "-qa" });
    listRpmsProcess.setCaptureOutput(true);

    ProcessExecutionResults executionResults = systemInfo.executeProcess(listRpmsProcess);
    String capturedOutput = executionResults.getCapturedOutput();

    // Process the resulting output
    if (capturedOutput == null) {
        return packages;
    }

    BufferedReader rpmNameReader = new BufferedReader(new StringReader(capturedOutput));

    String rpmName;

    while ((rpmName = rpmNameReader.readLine()) != null) {
        String name = null;
        String version = null;
        String architectureName = null;

        try {

            // Execute RPM query for each RPM
            ProcessExecution rpmQuery = new ProcessExecution(rpmExecutable);
            rpmQuery.setArguments(new String[] { "-q", "--qf",
                    "%{NAME}\\n%{VERSION}.%{RELEASE}\\n%{ARCH}\\n%{INSTALLTIME}\\n%{FILEMD5S}\\n%{GROUP}\\n%{FILENAMES}\\n%{SIZE}\\n%{LICENSE}\\n%{DESCRIPTION}",
                    rpmName });
            rpmQuery.setCaptureOutput(true);

            ProcessExecutionResults rpmDataResults = systemInfo.executeProcess(rpmQuery);
            String rpmData = rpmDataResults.getCapturedOutput();

            BufferedReader rpmDataReader = new BufferedReader(new StringReader(rpmData));

            name = rpmDataReader.readLine();
            version = rpmDataReader.readLine();
            architectureName = rpmDataReader.readLine();
            String installTimeString = rpmDataReader.readLine();
            String md5 = rpmDataReader.readLine();
            String category = rpmDataReader.readLine();
            String fileName = rpmDataReader.readLine();
            String sizeString = rpmDataReader.readLine();
            String license = rpmDataReader.readLine();

            StringBuffer description = new StringBuffer();
            String descriptionTemp;
            while ((descriptionTemp = rpmDataReader.readLine()) != null) {
                description.append(descriptionTemp);
            }

            Long fileSize = null;
            if (sizeString != null) {
                try {
                    fileSize = Long.parseLong(sizeString);
                } catch (NumberFormatException e) {
                    log.warn("Could not parse file size: " + sizeString);
                }
            }

            Long installTime = null;
            if (installTimeString != null) {
                try {
                    installTime = Long.parseLong(installTimeString);
                    installTime *= 1000L; // RPM returns epoch seconds, we need epoch millis
                } catch (NumberFormatException e) {
                    log.debug("Could not parse package install time");
                }
            }

            // There may be multiple file names. For now, just ignore the package (I'll find a better way
            // to deal with this going forward). There will be a blank space in the fileName attribute, so
            // just abort if we see that
            if ((fileName == null) || fileName.equals("")) {
                continue;
            }

            PackageDetailsKey key = new PackageDetailsKey(name, version, "rpm", architectureName);
            ResourcePackageDetails packageDetails = new ResourcePackageDetails(key);
            packageDetails.setClassification(category);
            packageDetails.setDisplayName(name);
            packageDetails.setFileName(fileName);
            if (!md5.startsWith("00000000000000000000000000000000")) {
                if (md5.length() <= 32) {
                    packageDetails.setMD5(md5);
                } else {
                    packageDetails.setSHA256(md5); // md5's can only be 32 chars, anything more and we assume its a SHA256
                }
            }
            packageDetails.setFileSize(fileSize);
            packageDetails.setLicenseName(license);
            packageDetails.setLongDescription(description.toString());
            packageDetails.setInstallationTimestamp(installTime);
            packages.add(packageDetails);
        } catch (Exception e) {
            log.error("Error creating resource package. RPM Name: " + rpmName + " Version: " + version
                    + " Architecture: " + architectureName);
        }

    }

    return packages;

}

From source file:org.romaframework.aspect.logging.loggers.FileLogger.java

public void print(int level, String category, String message) {
    Log logger = LogFactory.getLog(category);
    if (level == LoggingConstants.LEVEL_DEBUG) {
        logger.debug(message);//from ww  w  .j  av a  2 s. co m
    } else if (level == LoggingConstants.LEVEL_WARNING) {
        logger.warn(message);
    } else if (level == LoggingConstants.LEVEL_ERROR) {
        logger.error(message);
    } else if (level == LoggingConstants.LEVEL_FATAL) {
        logger.fatal(message);
    } else if (level == LoggingConstants.LEVEL_INFO) {
        logger.info(message);
    }

}