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

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

Introduction

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

Prototype

boolean isErrorEnabled();

Source Link

Document

Is error logging currently enabled?

Usage

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

/**
 * Get all available IRM types./*w  ww . j  a  v  a2s  . com*/
 * 
 * @return IRM types.
 */
public static SearchAccess[] getTypes() throws DSearchException {

    if (s_cachedSearchAccess != null) {
        return s_cachedSearchAccess;
    }

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

    final List<SearchAccess> found = new ArrayList<SearchAccess>();
    // TODO: Check why the next line is needed.
    // found.add(UNKNOWN);
    final IExtension[] extensions = Platform.getExtensionRegistry()
            .getExtensionPoint(EXTENSION_POINT_NAME_SEARCH_ACCESS).getExtensions();
    for (int i = 0; i < extensions.length; i++) {
        final IExtension extension = extensions[i];
        final IConfigurationElement[] configElements = extension.getConfigurationElements();

        for (int j = 0; j < configElements.length; j++) {
            final IConfigurationElement configurationElement = configElements[j];
            final String typeName = parseType(configurationElement, found.size());

            SearchAccess clazz = null;
            try {
                final Object obj = configurationElement.createExecutableExtension("Clazz");
                clazz = (SearchAccess) obj;
            } catch (final Exception exception) {
                if (log.isErrorEnabled()) {
                    if (configurationElement != null) {
                        log.error("Failed to instantiate search access");
                    } else {
                        log.error("Unknown!");
                    }
                }
                throw new DSearchException("unable to load search access", exception);
            }

            if (clazz != null) {
                found.add(clazz);
            }
        }
    }

    s_cachedSearchAccess = found.toArray(new SearchAccess[0]);
    return s_cachedSearchAccess;
}

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

/**
 * Parse configuration and return according IRMType.
 * /*w  w  w . j  a v a 2  s .c om*/
 * @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.jaxb.JaxbUtils.java

/**
 * Creates the validation event handler.
 * //from  w w  w .  jav  a 2s .c o m
 * @return the validation event handler
 */
public static ValidationEventHandler createValidationEventHandler() {
    return new ValidationEventHandler() {
        public boolean handleEvent(final ValidationEvent ve) {
            final Log log = LogFactory.getLog(JaxbUtils.class);
            if (ve.getSeverity() != ValidationEvent.WARNING) {
                final ValidationEventLocator vel = ve.getLocator();
                if (log.isErrorEnabled()) {
                    log.error("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:"
                            + ve.getMessage());
                }
                return false;
            }
            return true;
        }
    };
}

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

/**
 * Load schema runtime ex./*from w  w w . ja  va  2 s . c o m*/
 * 
 * @param bundle
 *          the bundle
 * @param resourcePath
 *          the resource path
 * 
 * @return the schema
 */
public static Schema loadSchemaRuntimeEx(final Bundle bundle, final String resourcePath) {
    final Log log = LogFactory.getLog(SchemaUtils.class);
    try {
        return loadSchema(bundle, resourcePath);
    } catch (Throwable e) {
        if (log.isErrorEnabled()) {
            log.error(e);
        }
        throw new RuntimeException(e);
    }
}

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.
 * //from  www. j a va2 s.  c o m
 * 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.inwiss.platform.common.util.StringUtil.java

/**
 * Encodes a string using algorithm specified in web.xml and return the
 * resulting encrypted password. If exception, the plain credentials
 * string is returned/*  ww  w  .  j  a v  a 2  s  .c o  m*/
 *
 * @param password  Password or other credentials to use in authenticating
 *                  this username
 * @param algorithm Algorithm used to do the digest
 * @return encypted password based on the algorithm.
 */
public static String encodePassword(String password, String algorithm) {

    if (password == null) {
        return null;
    }

    Log log = LogFactory.getLog(StringUtil.class);
    byte[] unencodedPassword = password.getBytes();

    MessageDigest md;

    try {
        // first create an instance, given the provider
        md = MessageDigest.getInstance(algorithm);
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        if (log.isErrorEnabled()) {
            log.error(sw.toString());
        }
        return password;
    }

    md.reset();

    // call the update method one or more times
    // (useful when you don't know the size of your data, e.g. stream)
    md.update(unencodedPassword);

    // now calculate the hash
    byte[] encodedPassword = md.digest();

    StringBuffer buf = new StringBuffer();

    for (int i = 0; i < encodedPassword.length; i++) {
        if ((encodedPassword[i] & 0xff) < 0x10) {
            buf.append("0");
        }

        buf.append(Long.toString(encodedPassword[i] & 0xff, 16));
    }

    return buf.toString();
}

From source file:org.jboss.netty.logging.CommonsLoggerTest.java

@Test
public void testIsErrorEnabled() {
    org.apache.commons.logging.Log mock = createStrictMock(org.apache.commons.logging.Log.class);

    expect(mock.isErrorEnabled()).andReturn(true);
    replay(mock);//from  www.j  av  a2  s.  c o m

    InternalLogger logger = new CommonsLogger(mock, "foo");
    assertTrue(logger.isErrorEnabled());
    verify(mock);
}

From source file:org.jboss.set.aphrodite.common.Utils.java

public static void logException(Log log, String message, Exception e) {
    if (log.isErrorEnabled()) {
        if (message == null)
            log.error(e);//w w  w.j a  va 2s .  co  m
        else
            log.error(message, e);
    }
}

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

/**
 * Wraps {@link Log#error(String)}/* ww w.ja  v a  2  s.  com*/
 * 
 * @param pattern to format against
 * @param objs an array of objects used as parameters to the <code>pattern</code>
 */
public static final void error(Object... objs) {
    Log log = getLogger();
    if (log.isErrorEnabled()) {
        getLogger().error(getMessage(objs));
    }
}

From source file:org.mule.api.processor.LoggerMessageProcessorTestCase.java

private Log buildMockLogger() {
    Log mockLogger = mock(Log.class);
    doNothing().when(mockLogger).error(any());
    doNothing().when(mockLogger).warn(any());
    doNothing().when(mockLogger).info(any());
    doNothing().when(mockLogger).debug(any());
    doNothing().when(mockLogger).trace(any());

    // All levels enabled by default
    when(mockLogger.isErrorEnabled()).thenReturn(true);
    when(mockLogger.isWarnEnabled()).thenReturn(true);
    when(mockLogger.isInfoEnabled()).thenReturn(true);
    when(mockLogger.isDebugEnabled()).thenReturn(true);
    when(mockLogger.isTraceEnabled()).thenReturn(true);
    return mockLogger;
}