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);

Source Link

Document

Logs a message with error log level.

Usage

From source file:com.siblinks.ws.common.BaseException.java

public void log(final Log log) {
    if (errorLevel.equals(ErrorLevel.INFO) && log.isDebugEnabled()) {
        log.debug("Info Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.debug(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.WARNING) && log.isWarnEnabled()) {
        log.warn("Warn Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.warn(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.ERROR) && log.isErrorEnabled()) {
        log.error("Error Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.error(StackTracer.getStackTrace(throwable));
    } else if (errorLevel.equals(ErrorLevel.FATAL) && log.isFatalEnabled()) {
        log.fatal("Fatal Message: ID - " + uniqueID + " User Message: " + userMessageKey);
        log.fatal(StackTracer.getStackTrace(throwable));
    }//from w w w .j a  v  a 2  s  .co m
    logged = true;
}

From source file:com.lolay.google.geocode.GeocodeIntegration.java

public void testReverse() throws Exception {
    Log log = testReverseLog;
    GeocodeClient client = new ClientFactory(baseUrl).getGeocode();
    GeocodeInvoker invoker = GeocodeInvoker.builder().latLng(40.714224D, -73.961452D).sensor(false).build();

    GeocodeResponse response = null;/* w w w . ja  v a  2  s . c  o  m*/
    try {
        long start = System.currentTimeMillis();
        response = invoker.geocode(client);
        long end = System.currentTimeMillis();
        log.trace(String.format("Reverse geocode took %s ms", end - start));
    } catch (Exception e) {
        log.error(e);
        fail();
    }
    assertNotNull(response);
    assertNotNull(response.getStatus());
    assertEquals(GeocodeStatus.OK, response.getStatus());
    assertNotNull(response.getResults());
    assertEquals(8, response.getResults().size());

    GeocodeResult result1 = response.getResults().get(0);
    assertNotNull(result1.getTypes());
    assertEquals(Arrays.asList(GeocodeResultType.STREET_ADDRESS), result1.getTypes());
    assertEquals("279-281 Bedford Ave, Brooklyn, NY 11211, USA", result1.getFormattedAddress());
    assertNotNull(result1.getAddressComponents());
    assertEquals(8, result1.getAddressComponents().size());

    GeocodeAddressComponent addressComponent1 = result1.getAddressComponents().get(0);
    assertNotNull(addressComponent1.getTypes());
    assertEquals(Arrays.asList(GeocodeAddressComponentType.STREET_NUMBER), addressComponent1.getTypes());
    assertNotNull(addressComponent1.getLongName());
    assertEquals("279-281", addressComponent1.getLongName());
    assertNotNull(addressComponent1.getShortName());
    assertEquals("279-281", addressComponent1.getShortName());

    GeocodeGeometry geometry = result1.getGeometry();
    assertNotNull(geometry);
    assertNotNull(geometry.getLocationType());
    assertEquals(GeocodeLocationType.RANGE_INTERPOLATED, geometry.getLocationType());
    validateLocation(geometry.getLocation(), 40.7142215D, -73.9614454D);
    validateFrame(geometry.getViewPort(), 40.7110552D, -73.9646313D, 40.7173505D, -73.9583361D);
    validateFrame(geometry.getBounds(), 40.7139010D, -73.9616800D, 40.7145047D, -73.9612874D);
}

From source file:com.lolay.placefinder.PlaceFinderIntegration.java

public void testWhere() throws Exception {
    final Log log = testWhereLog;
    log.trace("enter");

    PlaceFinderClient client = new PlaceFinderFactory(baseUrl).getPlaceFinder();

    PlaceFinderInvoker invoker = PlaceFinderInvoker.builder().appId(appId).count(1)
            .location("484 Los Angeles Ave., Moorpark, CA").flag("C").build();
    PlaceFinderResultSet response = null;
    try {/*  ww  w.jav  a 2s . c  o m*/
        long start = System.currentTimeMillis();
        response = invoker.location(client);
        long end = System.currentTimeMillis();
        log.trace(String.format("Query took %s ms", end - start));
    } catch (Exception e) {
        log.error(e);
        fail();
    }

    assertNotNull(response);
    assertEquals((Integer) 0, response.getError());

    PlaceFinderResult result = response.getResult();
    assertNotNull(result);
    assertNotNull(result.getLatitude());
    assertNotNull(result.getLongitude());
    assertTrue(result.getLatitude() > 0);
    assertTrue(result.getLongitude() < 0);
}

From source file:com.lolay.google.geocode.GeocodeIntegration.java

public void testForward() throws Exception {
    Log log = testForwardLog;
    GeocodeClient client = new ClientFactory(baseUrl).getGeocode();
    GeocodeInvoker invoker = GeocodeInvoker.builder().address("1600 Amphitheatre Parkway, Mountain View, CA")
            .sensor(false).build();// w ww.  j  av  a  2 s  . com

    GeocodeResponse response = null;
    try {
        long start = System.currentTimeMillis();
        response = invoker.geocode(client);
        long end = System.currentTimeMillis();
        log.trace(String.format("Forward geocode took %s ms", end - start));
    } catch (Exception e) {
        log.error(e);
        fail();
    }
    assertNotNull(response);
    assertNotNull(response.getStatus());
    assertEquals(GeocodeStatus.OK, response.getStatus());
    assertNotNull(response.getResults());
    assertEquals(1, response.getResults().size());

    GeocodeResult result1 = response.getResults().get(0);
    assertNotNull(result1.getTypes());
    assertEquals(Arrays.asList(GeocodeResultType.STREET_ADDRESS), result1.getTypes());
    assertEquals("1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", result1.getFormattedAddress());
    assertNotNull(result1.getAddressComponents());
    assertEquals(8, result1.getAddressComponents().size());

    GeocodeAddressComponent addressComponent1 = result1.getAddressComponents().get(0);
    assertNotNull(addressComponent1.getTypes());
    assertEquals(Arrays.asList(GeocodeAddressComponentType.STREET_NUMBER), addressComponent1.getTypes());
    assertNotNull(addressComponent1.getLongName());
    assertEquals("1600", addressComponent1.getLongName());
    assertNotNull(addressComponent1.getShortName());
    assertEquals("1600", addressComponent1.getShortName());

    GeocodeGeometry geometry = result1.getGeometry();
    assertNotNull(geometry);
    assertNotNull(geometry.getLocationType());
    assertEquals(GeocodeLocationType.ROOFTOP, geometry.getLocationType());
    validateLocation(geometry.getLocation(), 37.4227820D, -122.0850990D);
    validateFrame(geometry.getViewPort(), 37.4196344D, -122.0882466D, 37.4259296D, -122.0819514D);
    assertNull(geometry.getBounds());
}

From source file:com.lolay.placefinder.PlaceFinderIntegration.java

public void testReverse() throws Exception {
    final Log log = testReverseLog;
    log.trace("enter");

    PlaceFinderClient client = new PlaceFinderFactory(baseUrl).getPlaceFinder();

    PlaceFinderInvoker invoker = PlaceFinderInvoker.builder().appId(appId).count(1).latitude(37.787082F)
            .longitude(-122.400929F).geocodingFlag("R").build();
    PlaceFinderResultSet response = null;
    try {/*from   w  ww  .ja  v a2  s. c o m*/
        long start = System.currentTimeMillis();
        response = invoker.location(client);
        long end = System.currentTimeMillis();
        log.trace(String.format("Query took %s ms", end - start));
    } catch (Exception e) {
        log.error(e);
        fail();
    }

    assertNotNull(response);
    assertEquals((Integer) 0, response.getError());

    PlaceFinderResult result = response.getResult();
    assertNotNull(result);
    assertNotNull(result.getCounty());
    assertNotNull(result.getCity());
    assertNotNull(result.getState());
    assertNotNull(result.getStateCode());
}

From source file:io.smartspaces.workbench.project.test.JunitTestClassDetector.java

/**
 * Test the specified class for any test methods.
 *
 * <p>//from  www  .  j  av  a  2s.co m
 * Superclasses are searched.
 *
 * @param packagePrefix
 *          the prefix package path
 * @param classFileName
 *          the classname for the potential test class
 * @param classLoader
 *          the classloader for test classes
 * @param testClasses
 *          the growing list of classes to test
 * @param log
 *          the logger to use
 */
private void testClassForTests(StringBuilder packagePrefix, String classFileName, ClassLoader classLoader,
        List<Class<?>> testClasses, Log log) {
    StringBuilder fullyQualifiedClassName = new StringBuilder(packagePrefix);
    if (fullyQualifiedClassName.length() != 0) {
        fullyQualifiedClassName.append(CLASS_PACKAGE_COMPONENT_SEPARATOR);
    }
    fullyQualifiedClassName.append(classFileName.substring(0, classFileName.indexOf(FILE_EXTENSION_SEPARATOR)));
    try {
        Class<?> potentialTestClass = classLoader.loadClass(fullyQualifiedClassName.toString());

        if (isTestClass(potentialTestClass, log)) {
            testClasses.add(potentialTestClass);
        }
    } catch (Exception e) {
        log.error(String.format("Could not test class %s for test methods", fullyQualifiedClassName));
    }
}

From source file:edu.ucsb.nceas.mdqengine.solr.XMLtoJSON.java

@Override
public List<SolrElementField> getFields(Document doc, String identifier) throws Exception {
    List<SolrElementField> fields = new ArrayList<SolrElementField>();
    String xmlString = null;/*from ww  w.jav a 2  s . c om*/
    String jsonString = null;
    Log log = LogFactory.getLog(XMLtoJSON.class);

    // Convert the document that is being indexed to an XML string, then to a JSON string.
    // The field is stored as JSON so that it will be easy to parse by clients.
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);
        xmlString = writer.toString();

        JSONObject xmlJSONObj = XML.toJSONObject(xmlString);
        jsonString = xmlJSONObj.toString();
    } catch (TransformerException ex) {
        ex.printStackTrace();
        log.error("Error processing field " + this.name + ": " + ex.getMessage());
        return fields;
    } catch (JSONException je) {
        log.error("Error processing field " + this.name + ": " + je.getMessage());
        return fields;
    }

    fields.add(new SolrElementField(this.name, jsonString));
    return fields;
}

From source file:net.fenyo.mail4hotspot.service.AdvancedServicesImpl.java

@Override
public void testLog() {
    final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(getClass());

    log.trace("testlog: TRACE");
    log.fatal("testlog: FATAL");
    log.error("testlog: ERROR");
    log.info("testlog: INFO");
    log.debug("testlog: DEBUG");
    log.warn("testlog: WARN");
}

From source file:dk.statsbiblioteket.util.Logs.java

/**
 * Log the message and the elements to the log at the specified level.
 * Elements are converted to Strings and appended to the message. Arrays,
 * Lists and similar in the elements are expanded to a certain degree of
 * detail./*w  w  w  . j  a  va 2  s . c om*/
 *
 * Sample input/output:
 * <code>log(myLog, Level.TRACE, false, "Started test", null,
 * 5, new String[]{"flim", "flam"});</code>
 * expands to
 * <code>log.trace("Started test (5, (flim, flam))");</code>
 *
 * @param log      the log to log to.
 * @param level    the level to log to (e.g. TRACE, DEBUG, INFO...).
 * @param verbose  if true, the elements are expanded more than for false.
 * @param error    the cause of this logging. If null, no cause is logged.
 * @param message  the message for the log.
 * @param elements the elements to log.
 */
public static void log(Log log, Level level, String message, Throwable error, boolean verbose,
        Object... elements) {
    int maxLength = verbose ? VERBOSE_MAXLENGTH : DEFAULT_MAXLENGTH;
    int maxDepth = verbose ? VERBOSE_MAXDEPTH : DEFAULT_MAXDEPTH;
    String expanded = message;
    if (elements != null && elements.length > 0) {
        expanded += expand(elements, maxLength, maxDepth);
    }
    switch (level) {
    case TRACE:
        if (!log.isTraceEnabled()) {
            return;
        }
        if (error == null) {
            log.trace(expanded);
        } else {
            log.trace(expanded, error);
        }
        break;
    case DEBUG:
        if (!log.isDebugEnabled()) {
            return;
        }
        if (error == null) {
            log.debug(expanded);
        } else {
            log.debug(expanded, error);
        }
        break;
    case INFO:
        if (!log.isInfoEnabled()) {
            return;
        }
        if (error == null) {
            log.info(expanded);
        } else {
            log.info(expanded, error);
        }
        break;
    case WARN:
        if (!log.isWarnEnabled()) {
            return;
        }
        if (error == null) {
            log.warn(expanded);
        } else {
            log.warn(expanded, error);
        }
        break;
    case ERROR:
        if (!log.isErrorEnabled()) {
            return;
        }
        if (error == null) {
            log.error(expanded);
        } else {
            log.error(expanded, error);
        }
        break;
    case FATAL:
        if (!log.isFatalEnabled()) {
            return;
        }
        if (error == null) {
            log.fatal(expanded);
        } else {
            log.fatal(expanded, error);
        }
        break;
    default:
        throw new IllegalArgumentException("The level '" + level + "' is unknown");
    }
}

From source file:com.acc.web.manager.LogManager.java

private void log(Object logTypeObject, Object prefixObject, Object informationObject, LogType logType) {
    if (!AppLibConstant.isUseLog()) {
        return;//from w  ww  . j a  v  a2s  . co  m
    }
    Log log = logType == LogType.SYSTEMOUT || logType == LogType.FILE ? null : this.getLogger(logTypeObject);
    String logString = this.getLogString(prefixObject, informationObject);
    switch (logType) {
    case SYSTEMOUT:
        super.systemOut(logString);
        break;
    case FILE:
        super.fileOut(logString);
        break;
    case INFO:
        log.info(logString);
        break;
    case WARN:
        log.warn(logString);
        break;
    case DEBUG:
        log.debug(logString);
        break;
    case ERROR:
        log.error(logString);
        break;
    case FATAL:
        log.fatal(logString);
        break;
    }
}