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

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

Introduction

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

Prototype

void trace(Object message);

Source Link

Document

Logs a message with trace log level.

Usage

From source file:com.lolay.citygrid.content.places.search.SearchIntegration.java

public void testError() throws Exception {
    Log log = testErrorsLog;
    log.trace("ENTER");
    SearchClient searchProxy = new ClientFactory(baseUrl).getSearch();

    SearchInvoker search = SearchInvoker.builder().publisher("acme").type(SearchType.RESTAURANT)
            .where("abcdefghijklmnopqrstuvwxyz").placement("junit").build();
    try {//  ww w  .  j  a  v a 2s .  com
        search.where(searchProxy);
        fail();
    } catch (InvokerException e) {
        assertNotNull(e.getErrorCodes());
        assertEquals(1, e.getErrorCodes().size());
        assertEquals(ErrorCode.GEOCODE_FAILURE, e.getErrorCodes().get(0));
    } catch (WebApplicationException e) {
        log.error(e.getResponse(), e);
        fail();
    }
}

From source file:mockit.integration.logging.LoggingIntegrationsTest.java

@Test
public void commonsLoggingShouldLogNothing() {
    Log log1 = LogFactory.getLog("test");
    Log log2 = LogFactory.getLog(LoggingIntegrationsTest.class);

    assertFalse(log1.isTraceEnabled());//from   www .j  av a 2s. c  om
    log1.error("testing that log does nothing");
    assertFalse(log1.isDebugEnabled());
    log2.trace("test");
    log2.debug("testing that log does nothing");
}

From source file:com.lolay.citygrid.content.places.search.SearchIntegration.java

public void testWhereCorrection() throws Exception {
    Log log = testWhereCorrectionLog;
    log.trace("ENTER");
    SearchClient searchProxy = new ClientFactory(baseUrl).getSearch();

    SearchInvoker search = SearchInvoker.builder().publisher("acme").what("computr parts").where("90069")
            .placement("junit").build();
    SearchResults results = null;// ww w  .j ava 2 s. c  o m
    try {
        results = search.where(searchProxy);
    } catch (WebApplicationException e) {
        log.error(e.getResponse(), e);
        fail();
    }
    assertNotNull(results);
    assertNotNull(results.getTotalHits());
    assertEquals((Integer) 0, results.getTotalHits());
    assertNotNull(results.getDidYouMean());
    assertEquals((Integer) 1, results.getFirstHit());
    assertEquals((Integer) 0, results.getLastHit());
    assertNotNull(results.getUri());
    assertNotNull(results.getRegions());
    assertTrue(results.getRegions().size() > 0);
    for (SearchRegion region : results.getRegions()) {
        assertNotNull(region.getType());
        assertNotNull(region.getLatitude());
        assertNotNull(region.getLongitude());
        assertNotNull(region.getDefaultRadius());
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet.java

/**
 * If logging on the subclass is set to the TRACE level, dump the HTTP
 * headers on the request./*from  www . ja v  a  2  s. c  o m*/
 */
private void dumpRequestHeaders(HttpServletRequest req) {
    @SuppressWarnings("unchecked")
    Enumeration<String> names = req.getHeaderNames();

    Log subclassLog = LogFactory.getLog(this.getClass());
    subclassLog.trace("----------------------request:" + req.getRequestURL());
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        if (!BORING_HEADERS.contains(name)) {
            subclassLog.trace(name + "=" + req.getHeader(name));
        }
    }
}

From source file:com.lolay.citygrid.content.places.search.SearchIntegration.java

public void testWhere() throws Exception {
    Log log = testWhereLog;
    log.trace("ENTER");
    SearchClient searchProxy = new ClientFactory(baseUrl).getSearch();

    SearchInvoker search = SearchInvoker.builder().publisher("acme").type(SearchType.RESTAURANT).where("90069")
            .placement("junit").histograms(true).build();
    SearchResults results = null;/*from w w  w.j a  va 2 s  .  com*/
    try {
        long start = System.currentTimeMillis();
        results = search.where(searchProxy);
        long end = System.currentTimeMillis();
        log.trace(String.format("Location search took %s ms", end - start));
    } catch (WebApplicationException e) {
        log.error(e.getResponse(), e);
        fail();
    }
    assertNotNull(results);
    assertNotNull(results.getTotalHits());
    assertTrue(results.getTotalHits() > 0);
    assertNull(results.getDidYouMean());
    assertEquals((Integer) 1, results.getFirstHit());
    assertEquals((Integer) 20, results.getLastHit());
    assertNotNull(results.getUri());
    assertNotNull(results.getRegions());
    assertTrue(results.getRegions().size() > 0);
    for (SearchRegion region : results.getRegions()) {
        assertNotNull(region.getType());
        assertNotNull(region.getLatitude());
        assertNotNull(region.getLongitude());
        assertNotNull(region.getDefaultRadius());
    }

    assertNotNull(results.getLocations());
    assertTrue(results.getLocations().size() > 0);
    boolean ratingChecked = false;
    boolean imageChecked = false;
    for (SearchLocation location : results.getLocations()) {
        assertNotNull(location.getId());
        assertNotNull(location.getImpressionId());
        assertNotNull(location.getFeatured());
        assertNotNull(location.getName());
        assertNotNull(location.getAddress());
        assertNotNull(location.getLatitude());
        assertNotNull(location.getLongitude());
        assertNotNull(location.getProfile());
        assertNotNull(location.getHasVideo());
        assertNotNull(location.getHasOffers());
        assertNotNull(location.getUserReviewCount());
        assertNotNull(location.getSampleCategories());
        if (location.getId().equals(101344)) {
            assertNotNull(location.getRating());
            ratingChecked = true;
        }
        if (location.getId().equals(101409)) {
            assertNotNull(location.getImage());
            imageChecked = true;
        }
    }
    assertTrue(ratingChecked);
    assertTrue(imageChecked);

    assertNotNull(results.getHistograms());
    assertTrue(results.getHistograms().size() > 0);
    for (SearchHistogram histogram : results.getHistograms()) {
        assertNotNull(histogram.getName());
        assertNotNull(histogram.getItems());
        assertTrue(histogram.getItems().size() > 0);
        for (SearchHistogramItem item : histogram.getItems()) {
            assertNotNull(item.getName());
            assertNotNull(item.getCount());
            assertTrue(item.getCount() > 0);
            assertNotNull(item.getUri());
        }
    }
}

From source file:com.lolay.citygrid.content.places.search.SearchIntegration.java

public void testLatLon() throws Exception {
    Log log = testLatLonLog;
    log.trace("ENTER");
    SearchClient searchProxy = new ClientFactory(baseUrl).getSearch();

    SearchInvoker search = SearchInvoker.builder().publisher("acme").type(SearchType.RESTAURANT)
            .latitude(34.0522222D).longitude(-118.2427778D).placement("junit").histograms(true).build();
    SearchResults results = null;/*  w w w  . j  a v a  2 s.  c o m*/
    try {
        long start = System.currentTimeMillis();
        results = search.latlon(searchProxy);
        long end = System.currentTimeMillis();
        log.trace(String.format("Location search took %s ms", end - start));
    } catch (WebApplicationException e) {
        log.error(e.getResponse(), e);
        fail();
    }
    assertNotNull(results);
    assertNotNull(results.getTotalHits());
    assertTrue(results.getTotalHits() > 0);
    assertNull(results.getDidYouMean());
    assertEquals((Integer) 1, results.getFirstHit());
    assertEquals((Integer) 20, results.getLastHit());
    assertNotNull(results.getUri());
    assertNotNull(results.getRegions());
    for (SearchRegion region : results.getRegions()) {
        assertNotNull(region.getType());
        assertNotNull(region.getLatitude());
        assertNotNull(region.getLongitude());
        assertNotNull(region.getDefaultRadius());
    }

    assertNotNull(results.getLocations());
    assertTrue(results.getLocations().size() > 0);
    boolean ratingChecked = false;
    boolean imageChecked = false;
    for (SearchLocation location : results.getLocations()) {
        assertNotNull(location.getId());
        assertNotNull(location.getImpressionId());
        assertNotNull(location.getFeatured());
        assertNotNull(location.getName());
        assertNotNull(location.getAddress());
        assertNotNull(location.getLatitude());
        assertNotNull(location.getLongitude());
        assertNotNull(location.getProfile());
        assertNotNull(location.getHasVideo());
        assertNotNull(location.getHasOffers());
        assertNotNull(location.getUserReviewCount());
        assertNotNull(location.getSampleCategories());
        if (location.getId().equals(46312464)) {
            assertNotNull(location.getRating());
            ratingChecked = true;
        }
        if (location.getId().equals(46312464)) {
            assertNotNull(location.getImage());
            imageChecked = true;
        }
    }
    assertTrue(ratingChecked);
    assertTrue(imageChecked);

    assertNotNull(results.getHistograms());
    assertTrue(results.getHistograms().size() > 0);
    for (SearchHistogram histogram : results.getHistograms()) {
        assertNotNull(histogram.getName());
        assertNotNull(histogram.getItems());
        assertTrue(histogram.getItems().size() > 0);
        for (SearchHistogramItem item : histogram.getItems()) {
            assertNotNull(item.getName());
            assertNotNull(item.getCount());
            assertTrue(item.getCount() > 0);
            assertNotNull(item.getUri());
        }
    }
}

From source file:javadz.beanutils.MethodUtils.java

/**
 * <p>Find an accessible method that matches the given name and has compatible parameters.
 * Compatible parameters mean that every method parameter is assignable from 
 * the given parameters./*from  w w w  .  j  a v  a2s . co  m*/
 * In other words, it finds a method with the given name 
 * that will take the parameters given.<p>
 *
 * <p>This method is slightly undeterminstic since it loops 
 * through methods names and return the first matching method.</p>
 * 
 * <p>This method is used by 
 * {@link 
 * #invokeMethod(Object object,String methodName,Object [] args,Class[] parameterTypes)}.
 *
 * <p>This method can match primitive parameter by passing in wrapper classes.
 * For example, a <code>Boolean</code> will match a primitive <code>boolean</code>
 * parameter.
 *
 * @param clazz find method in this class
 * @param methodName find method with this name
 * @param parameterTypes find method with compatible parameters 
 * @return The accessible method
 */
public static Method getMatchingAccessibleMethod(Class clazz, String methodName, Class[] parameterTypes) {
    // trace logging
    Log log = LogFactory.getLog(MethodUtils.class);
    if (log.isTraceEnabled()) {
        log.trace("Matching name=" + methodName + " on " + clazz);
    }
    MethodDescriptor md = new MethodDescriptor(clazz, methodName, parameterTypes, false);

    // see if we can find the method directly
    // most of the time this works and it's much faster
    try {
        // Check the cache first
        Method method = getCachedMethod(md);
        if (method != null) {
            return method;
        }

        method = clazz.getMethod(methodName, parameterTypes);
        if (log.isTraceEnabled()) {
            log.trace("Found straight match: " + method);
            log.trace("isPublic:" + Modifier.isPublic(method.getModifiers()));
        }

        setMethodAccessible(method); // Default access superclass workaround

        cacheMethod(md, method);
        return method;

    } catch (NoSuchMethodException e) {
        /* SWALLOW */ }

    // search through all methods 
    int paramSize = parameterTypes.length;
    Method bestMatch = null;
    Method[] methods = clazz.getMethods();
    float bestMatchCost = Float.MAX_VALUE;
    float myCost = Float.MAX_VALUE;
    for (int i = 0, size = methods.length; i < size; i++) {
        if (methods[i].getName().equals(methodName)) {
            // log some trace information
            if (log.isTraceEnabled()) {
                log.trace("Found matching name:");
                log.trace(methods[i]);
            }

            // compare parameters
            Class[] methodsParams = methods[i].getParameterTypes();
            int methodParamSize = methodsParams.length;
            if (methodParamSize == paramSize) {
                boolean match = true;
                for (int n = 0; n < methodParamSize; n++) {
                    if (log.isTraceEnabled()) {
                        log.trace("Param=" + parameterTypes[n].getName());
                        log.trace("Method=" + methodsParams[n].getName());
                    }
                    if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) {
                        if (log.isTraceEnabled()) {
                            log.trace(methodsParams[n] + " is not assignable from " + parameterTypes[n]);
                        }
                        match = false;
                        break;
                    }
                }

                if (match) {
                    // get accessible version of method
                    Method method = getAccessibleMethod(clazz, methods[i]);
                    if (method != null) {
                        if (log.isTraceEnabled()) {
                            log.trace(method + " accessible version of " + methods[i]);
                        }
                        setMethodAccessible(method); // Default access superclass workaround
                        myCost = getTotalTransformationCost(parameterTypes, method.getParameterTypes());
                        if (myCost < bestMatchCost) {
                            bestMatch = method;
                            bestMatchCost = myCost;
                        }
                    }

                    log.trace("Couldn't find accessible method.");
                }
            }
        }
    }
    if (bestMatch != null) {
        cacheMethod(md, bestMatch);
    } else {
        // didn't find a match
        log.trace("No match found.");
    }

    return bestMatch;
}

From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the given message to the log at the trace level. If the log level is not enabled, this method does
 * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned.
 *
 * @param  log     the log where the messages will go
 * @param  key     the resource bundle key name
 * @param  varargs arguments to help fill in the resource bundle message
 *
 * @return if the message was logged, a non-<code>null</code> Msg object is returned
 *//* w ww.  j a va 2 s .com*/
public static Msg trace(Log log, String key, Object... varargs) {
    if (log.isTraceEnabled()) {
        Msg msg = Msg.createMsg(key, varargs);
        log.trace((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg);
        return msg;
    }

    return null;
}

From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the given message to the log at the trace level. If the log level is not enabled, this method does
 * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned.
 *
 * @param  log     the log where the messages will go
 * @param  locale  the locale to determine what bundle to use
 * @param  key     the resource bundle key name
 * @param  varargs arguments to help fill in the resource bundle message
 *
 * @return if the message was logged, a non-<code>null</code> Msg object is returned
 *//*from ww  w  . j av  a 2  s  . c om*/
public static Msg trace(Log log, Locale locale, String key, Object... varargs) {
    if (log.isTraceEnabled()) {
        Msg msg = Msg.createMsg(locale, key, varargs);
        log.trace((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg);
        return msg;
    }

    return null;
}

From source file:com.sos.i18n.logging.commons.CommonsLogMsg.java

/**
 * Logs the given message to the log at the trace level. If the log level is not enabled, this method does
 * nothing and returns <code>null</code>. If a message was logged, its {@link Msg} will be returned.
 *
 * @param  log      the log where the messages will go
 * @param  basename the base name of the resource bundle
 * @param  key      the resource bundle key name
 * @param  varargs  arguments to help fill in the resource bundle message
 *
 * @return if the message was logged, a non-<code>null</code> Msg object is returned
 *///  w w w .  j  av  a  2s. c o  m
public static Msg trace(Log log, BundleBaseName basename, String key, Object... varargs) {
    if (log.isTraceEnabled()) {
        Msg msg = Msg.createMsg(basename, key, varargs);
        log.trace((Logger.getDumpLogKeys()) ? ('{' + key + '}' + msg) : msg);
        return msg;
    }

    return null;
}