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

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

Introduction

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

Prototype

void error(Object message, Throwable t);

Source Link

Document

Logs an error with error log level.

Usage

From source file:org.eclipse.smila.search.utils.indexstructure.IndexStructureAccess.java

/**
 * Parse configuration and return according IRMType.
 * //from w  w  w  . j  a  v a  2s  .c  o m
 * @param configurationElement
 *          Configuration element.
 * @param ordinal
 *          Ordinal.
 * @return Type name.
 */
public static String parseType(IConfigurationElement configurationElement, int ordinal) {

    if (!configurationElement.getName().equals("IndexStructureAccess")) {
        return null;
    }

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

    try {
        String name = configurationElement.getAttribute("Clazz");
        if (name == null) {
            name = "[missing attribute name]";
        }
        return name;
    } catch (final Exception e) {
        if (log.isErrorEnabled()) {
            String name = configurationElement.getAttribute("Clazz");
            if (name == null) {
                name = "[missing attribute name]";
            }
            final String msg = "Failed to load StrategyType named " + name + " in "
                    + configurationElement.getDeclaringExtension().getNamespaceIdentifier();
            log.error(msg, e);
        }
        return null;
    }
}

From source file:org.eclipse.smila.search.utils.search.SearchAccess.java

/**
 * Parse configuration and return according IRMType.
 * /*w ww .j a va  2s  . com*/
 * @param configurationElement
 *          Configuration element.
 * @param ordinal
 *          Ordinal.
 * @return Type name.
 */
public static String parseType(IConfigurationElement configurationElement, int ordinal) {

    if (!configurationElement.getName().equals("SearchAccess")) {
        return null;
    }

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

    try {
        String name = configurationElement.getAttribute("Clazz");
        if (name == null) {
            name = "[missing attribute name]";
        }
        return name;
    } catch (final Exception e) {
        if (log.isErrorEnabled()) {
            String name = configurationElement.getAttribute("Clazz");
            if (name == null) {
                name = "[missing attribute name]";
            }
            final String msg = "Failed to load search type named " + name + " in "
                    + configurationElement.getDeclaringExtension().getNamespaceIdentifier();
            log.error(msg, e);
        }
        return null;
    }
}

From source file:org.eclipse.smila.utils.xml.XMLUtils.java

/**
 * A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD <strong>NOT </strong> be seen by the
 * user, not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs.
 * /*ww  w  .j  a  v a2  s.com*/
 * Usage: Add an id field (type java.lang.String) to your EJB, and add setId(XXXUtil.generateGUID(this)); to the
 * ejbCreate method.
 * 
 * @return String
 * @param o
 *          -
 */
public static final String generateGUID(Object o) {
    final Log log = LogFactory.getLog(XMLUtils.class);
    final StringBuffer tmpBuffer = new StringBuffer(16);
    if (s_hexServerIP == null) {
        java.net.InetAddress localInetAddress = null;
        try {
            // get the inet address
            localInetAddress = java.net.InetAddress.getLocalHost();
        } catch (final java.net.UnknownHostException uhe) {
            if (log.isErrorEnabled()) {
                log.error(
                        "ConfigurationUtil: Could not get the local IP address using InetAddress.getLocalHost()!",
                        uhe);
            }
            return null;
        }
        final byte[] serverIP = localInetAddress.getAddress();
        s_hexServerIP = hexFormat(getInt(serverIP), 8);
    }
    final String hashcode = hexFormat(System.identityHashCode(o), 8);
    tmpBuffer.append(s_hexServerIP);
    tmpBuffer.append(hashcode);

    final long timeNow = System.currentTimeMillis();
    final int timeLow = (int) timeNow & 0xFFFFFFFF;
    final int node = SEEDER.nextInt();

    final StringBuffer guid = new StringBuffer(32);
    guid.append(hexFormat(timeLow, 8));
    guid.append(tmpBuffer.toString());
    guid.append(hexFormat(node, 8));
    return guid.toString();
}

From source file:org.hyperic.hq.context.IntegrationTestContextLoader.java

public static final void configureSigar(final ApplicationContext context, final Log externalLogger) {
    final Log log = (externalLogger == null ? logger : externalLogger);

    try {//  ww w.  j ava  2 s . c  o  m
        overrideProperties(log);

        //Find the sigar libs on the test classpath
        final File sigarBin = new File(
                context.getResource("/libsigar-sparc64-solaris.so").getFile().getParent());
        log.info("Setting sigar path to : " + sigarBin.getAbsolutePath());
        System.setProperty("org.hyperic.sigar.path", sigarBin.getAbsolutePath());

        //ensure that the Sigar native libraries are loaded and remain in the classloader's context 
        sigar = new Sigar();
        Sigar.load();

    } catch (Throwable t) {
        log.error("Unable to initiailize sigar path", t);
        throw new SystemException(t);
    } //EO catch block
}

From source file:org.hyperic.hq.ui.action.resource.service.inventory.ViewServiceAction.java

/**
 * Retrieve this data and store it in the <code>ServerForm</code>:
 * //from   ww w. j  av  a 2 s.c  o  m
 */
public ActionForward execute(ComponentContext context, ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(ViewServiceAction.class.getName());

    try {
        ServiceValue service = (ServiceValue) RequestUtils.getResource(request);

        Integer sessionId = RequestUtils.getSessionId(request);
        AppdefEntityID entityId = service.getEntityId();

        PageControl pcg = RequestUtils.getPageControl(request, "psg", "png", "sog", "scg");

        List<AppdefGroupValue> groups = appdefBoss.findAllGroupsMemberInclusive(sessionId.intValue(), pcg,
                service.getEntityId());
        // check to see if this thing is a platform service
        if (service.getServer().getServerType().getVirtual()) {
            // find the platform resource and add it to the request scope
            try {
                PlatformValue pv = appdefBoss.findPlatformByDependentID(sessionId.intValue(), entityId);
                request.setAttribute(Constants.PARENT_RESOURCE_ATTR, pv);
            } catch (PermissionException pe) {
                // TODO Would like to able to fall back and grab the name
                // through other means
                // which isn't easily done right now. Only thing we should
                // prevent
                // in the case of an error is plain text instead of a link.
                log.error("insufficient permissions for parent platform ", pe);

                RequestUtils.setError(request, "resource.service.inventory.error.ViewParentPlatformPermission");
                request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS, new ArrayList());
                request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS_COUNT, new Integer(0));
                request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS, new ArrayList());
                request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS_COUNT, new Integer(0));
                return null;
            }
        }
        request.setAttribute(Constants.ALL_RESGRPS_ATTR, groups);
        if (service == null) {
            RequestUtils.setError(request, "resource.service.error.ServiceNotFound");
            return null;
        }

        // create and initialize the remove resource groups form
        RemoveResourceGroupsForm rmGroupsForm = new RemoveResourceGroupsForm();
        rmGroupsForm.setRid(service.getId());
        rmGroupsForm.setType(new Integer(service.getEntityId().getType()));

        int psg = RequestUtils.getPageSize(request, "psg");
        rmGroupsForm.setPsg(new Integer(psg));

        request.setAttribute(Constants.RESOURCE_REMOVE_GROUPS_MEMBERS_FORM_ATTR, rmGroupsForm);

        log.debug("AppdefEntityID = " + entityId.toString());

        ConfigSchema config = new ConfigSchema();
        ConfigResponse oldResponse = new ConfigResponse();
        boolean editConfig = false;

        try {
            oldResponse = productBoss.getMergedConfigResponse(sessionId.intValue(), ProductPlugin.TYPE_PRODUCT,
                    entityId, false);
            config = productBoss.getConfigSchema(sessionId.intValue(), entityId, ProductPlugin.TYPE_PRODUCT,
                    oldResponse);

            editConfig = true;
        } catch (ConfigFetchException e) {
            log.warn("Managed Exception ConfigFetchException caught " + e.toString());
        } catch (PluginNotFoundException e) {
            log.warn("Managed Exception PluginNotFoundException caught " + e.toString());
        }

        List<ConfigValues> uiProductOptions = ActionUtils.getConfigValues(config, oldResponse);

        request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS, uiProductOptions);
        request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS_COUNT, new Integer(uiProductOptions.size()));

        config = new ConfigSchema();
        oldResponse = new ConfigResponse();

        try {
            oldResponse = productBoss.getMergedConfigResponse(sessionId.intValue(),
                    ProductPlugin.TYPE_MEASUREMENT, entityId, false);
            config = productBoss.getConfigSchema(sessionId.intValue(), entityId, ProductPlugin.TYPE_MEASUREMENT,
                    oldResponse);
        } catch (ConfigFetchException e) {
            // do nothing
        } catch (PluginNotFoundException e) {
            // do nothing
        }

        setUIOptions(service, request, config, oldResponse);

        config = new ConfigSchema();

        oldResponse = productBoss.getMergedConfigResponse(sessionId.intValue(), ProductPlugin.TYPE_CONTROL,
                entityId, false);
        try {
            config = productBoss.getConfigSchema(sessionId.intValue(), entityId, ProductPlugin.TYPE_CONTROL,
                    oldResponse);
        } catch (PluginNotFoundException e) {
            // do nothing
        }

        List<ConfigValues> uiControlOptions = ActionUtils.getConfigValues(config, oldResponse);

        request.setAttribute(Constants.CONTROL_CONFIG_OPTIONS, uiControlOptions);
        request.setAttribute(Constants.CONTROL_CONFIG_OPTIONS_COUNT, new Integer(uiControlOptions.size()));

        request.setAttribute(Constants.AUTO_INVENTORY,
                new Boolean(service.getServer().getRuntimeAutodiscovery()));

        if (!editConfig)
            RequestUtils.setError(request, "resource.common.inventory.error.serverConfigNotSet",
                    "configServer");
        request.setAttribute(Constants.EDIT_CONFIG, new Boolean(editConfig));

        setConfigModifier(request, entityId);

        return null;

    } catch (ApplicationException e) {
        log.error("unable to retrieve configuration properties ", e);
        RequestUtils.setError(request, "resource.common.inventory.error.configRetrieveError");
        request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS, new ArrayList());
        request.setAttribute(Constants.PRODUCT_CONFIG_OPTIONS_COUNT, new Integer(0));
        request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS, new ArrayList());
        request.setAttribute(Constants.MONITOR_CONFIG_OPTIONS_COUNT, new Integer(0));
        return null;
    }
}

From source file:org.hyperic.util.file.match.Matcher.java

private FileSystem[] loadFilesystems(MatcherConfig config) throws SigarException {

    Log log = config.getLog();
    FileSystem[] filesystems;//from  ww  w  .j ava 2  s  .  c  o m

    if (config.getFSTypes() != MatcherConfig.FS_ALL) {
        Sigar sigar = new Sigar();
        try {
            filesystems = sigar.getFileSystemList();
            return filesystems;

        } catch (SigarException se) {
            if (log != null) {
                log.error("matcher: error getting " + "available filesystems:" + se, se);
            }
            throw se;

        } finally {
            sigar.close();
        }
    }
    return null;
}

From source file:org.hyperic.util.file.match.Matcher.java

/**
 * Get the matches for this search.//w  w  w  . ja  va  2 s .  c o  m
 * @return A Map representing the matches.  The keys in the Map are
 * the keys that each MatchSelector in the MatcherConfig was
 * initialized with in its constructor.  The values are Lists, where
 * each element in the List is a String representing the full path
 * of the matched path.
 * @exception MatcherInterruptedException If the search was interrupted
 * before it could be completed.  In this case, you can get the matches
 * so far by calling getMatchesSoFar on the MatcherInterruptedException
 * object.
 * @exception SigarException If an error occurs reading the available
 * filesystems - this can only happen if the config's getFSTypes returns
 * a value other than MatcherConfig.FS_ALL.
 */
public synchronized MatchResults getMatches(MatcherConfig config)
        throws MatcherInterruptedException, SigarException {

    int i, j;
    List scanners;
    MatcherScanner scanner;
    MatchResults results = new MatchResults();
    File f;
    Log log = config.getLog();
    FileSystem[] filesystems = null;

    filesystems = loadFilesystems(config);
    scanners = initScanners(config, filesystems, results);

    for (i = 0; i < scanners.size(); i++) {

        scanner = (MatcherScanner) scanners.get(i);
        scanner.initMatches(results.matches);

        try {
            scanner.doScan();

        } catch (MatcherInterruptedException mie) {
            mie.setMatchesSoFar(scanner.getMatches());
            if (log != null) {
                log.warn("matcher: search interrupted.");
            }
            throw mie;

        } catch (Exception e) {
            // huh?
            scanner.addError(new MatcherException("matcher: search error", e));
            if (log != null) {
                log.error("matcher: search error: " + e, e);
            }
        }

        results.matches = scanner.getMatches();
        if (log != null) {
            log.debug("results.matches=" + results.matches);
        }
        results.errors.addAll(scanner.getErrors());
    }

    return results;
}

From source file:org.integratedmodelling.thinklab.commandline.Shell.java

public static void runScript(String s, ISession session, Log log) throws ThinklabException {

    for (String input : MiscUtilities.readFileIntoStrings(s)) {

        input = input.trim();/* w w w  . j  a va2 s .co  m*/
        if (input == null || input.isEmpty() || input.startsWith("#"))
            continue;

        if ("exit".equals(input)) {
            break;
        } else {

            try {

                Command cmd = CommandParser.parse(input);

                if (cmd == null)
                    continue;

                IValue result = CommandManager.get().submitCommand(cmd, session);
                if (result != null)
                    log.info(cmd + " -> " + result.toString());

            } catch (ThinklabException e) {
                log.error("executing " + input, e);
            }
        }
    }

}

From source file:org.intermine.common.swing.WindowUtils.java

/**
 * Show a standard exception dialog./*from   ww w. ja  va  2 s  .  co m*/
 * 
 * @param parent The parent Window.
 * @param error The exception.
 * @param titleMessageKey Message key for the title of the window.
 * @param bodyMessageKey Message key for the body of the window.
 * @param logger The logger to write the error message to.
 */
public static void showExceptionDialog(Window parent, Throwable error, String titleMessageKey,
        String bodyMessageKey, Log logger) {
    if (logger == null) {
        logger = LogFactory.getLog(WindowUtils.class);
    }

    String displayMessage;
    if (error.getCause() != null) {
        logger.error(Messages.getMessage(bodyMessageKey, ""), error.getCause());
        StringWriter swriter = new StringWriter();
        PrintWriter writer = new PrintWriter(swriter);
        error.getCause().printStackTrace(writer);
        writer.close();

        displayMessage = Messages.getMessage(bodyMessageKey, swriter.toString());
    } else {
        logger.error(Messages.getMessage(bodyMessageKey, ""), error);
        displayMessage = Messages.getMessage(bodyMessageKey, error.getMessage());
    }

    JOptionPane.showMessageDialog(parent, displayMessage, Messages.getMessage(titleMessageKey),
            JOptionPane.ERROR_MESSAGE);
}

From source file:org.jasig.portal.spring.PortalApplicationContextLocator.java

/**
 * If running in a web application the existing {@link WebApplicationContext} will be returned. if
 * not a singleton {@link ApplicationContext} is created if needed and returned. Unless a {@link WebApplicationContext}
 * is specifically needed this method should be used as it will work both when running in and out
 * of a web application//from   w w  w  . j a va  2 s  .  co  m
 * 
 * @return The {@link ApplicationContext} for the portal. 
 */
public static ApplicationContext getApplicationContext() {
    Log logger = LogFactory.getLog(LOGGER_NAME);
    final ServletContext context = servletContext;

    if (context != null) {
        logger.debug("Using WebApplicationContext");

        if (applicationContextCreator.isCreated()) {
            final IllegalStateException createException = new IllegalStateException(
                    "A portal managed ApplicationContext has already been created but now a ServletContext is available and a WebApplicationContext will be returned. "
                            + "This situation should be resolved by delaying calls to this class until after the web-application has completely initialized.");
            logger.error(createException, createException);
            logger.error("Stack trace of original ApplicationContext creator", directCreatorThrowable);
            throw createException;
        }

        final WebApplicationContext webApplicationContext = WebApplicationContextUtils
                .getWebApplicationContext(context);
        if (webApplicationContext == null) {
            throw new IllegalStateException(
                    "ServletContext is available but WebApplicationContextUtils.getWebApplicationContext(ServletContext) returned null. Either the application context failed to load or is not yet done loading.");
        }
        return webApplicationContext;
    }

    return applicationContextCreator.get();
}