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:interactivespaces.controller.runtime.StandardSpaceController.java

@Override
public void startup() {
    super.startup();

    confirmUuid();// w  w  w .j a v  a  2 s.  com

    final Log log = getSpaceEnvironment().getLog();

    spaceControllerCommunicator.onStartup();

    controllerHeartbeat = spaceControllerCommunicator.newSpaceControllerHeartbeat();
    controllerHeartbeatControl = getSpaceEnvironment().getExecutorService().scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            try {
                controllerHeartbeat.sendHeartbeat();
            } catch (Exception e) {
                log.error("Exception while trying to send a Space Controller heartbeat", e);
            }
        }
    }, heartbeatDelay, heartbeatDelay, TimeUnit.MILLISECONDS);

    dataBundleManager.startup();

    startupControllerControl();
    startupCoreControllerServices();

    startupAutostartActivities();

    spaceControllerCommunicator.notifyRemoteMasterServerAboutStartup(getControllerInfo());

    startedUp = true;
}

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;/*from ww w . ja 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:net.sf.jabb.util.ex.LoggedException.java

/**
 * Create a new instance, and at the same time, ensure the original exception is logged.
 * //  w  w w.  ja v a2 s. c  om
 * @param log      the log utility
 * @param level      level of the log
 * @param message   description
 * @param cause      the original exception. If it is of type LoggedException, 
 *                then the newly created instance is a clone of itself.
 */
public LoggedException(Log log, int level, String message, Throwable cause) {
    super(cause instanceof LoggedException ? cause.getMessage() : message,
            cause instanceof LoggedException ? cause.getCause() : cause);
    if (!(cause instanceof LoggedException)) {
        switch (level) {
        case TRACE:
            if (log.isTraceEnabled()) {
                log.trace(message, cause);
            }
            break;
        case DEBUG:
            if (log.isDebugEnabled()) {
                log.debug(message, cause);
            }
            break;
        case WARN:
            if (log.isWarnEnabled()) {
                log.warn(message, cause);
            }
            break;
        case FATAL:
            log.fatal(message, cause);
            break;
        case INFO:
            log.info(message, cause);
            break;
        default:
            log.error(message, cause);
        }
    }
}

From source file:de.ingrid.iplug.csw.dsc.cache.impl.AbstractUpdateStrategy.java

/**
 * Fetch all records from a id list using the GetRecordById and put them in the cache
 * //from w ww .  j a  va  2 s . co m
 * @param client The CSWClient to use
 * @param elementSetName The ElementSetName of the records to fetch
 * @param recordIds The list of ids
 * @param requestPause The time between two requests in milliseconds
 * @throws Exception
 */
protected void fetchRecords(CSWClient client, ElementSetName elementSetName, List<String> recordIds,
        int requestPause) throws Exception {

    CSWFactory factory = client.getFactory();
    Cache cache = this.getExecutionContext().getCache();
    Log log = this.getLog();

    CSWQuery query = factory.createQuery();
    query.setElementSetName(elementSetName);

    int cnt = 1;
    int max = recordIds.size();
    Iterator<String> it = recordIds.iterator();
    while (it.hasNext()) {
        String id = it.next();
        query.setId(id);
        CSWRecord record = null;
        try {
            record = client.getRecordById(query);
            if (log.isDebugEnabled())
                log.debug("Fetched record: " + id + " " + record.getElementSetName() + " (" + cnt + "/" + max
                        + ")");
            cache.putRecord(record);
        } catch (Exception e) {
            log.error("Error fetching record '" + query.getId() + "'! Removing record from cache.", e);
            cache.removeRecord(query.getId());
            recordIds.remove(id);
        }
        cnt++;
        Thread.sleep(requestPause);
    }
}

From source file:com.dhcc.framework.web.context.DhccContextLoader.java

private boolean isMicrokernelStart(ServletContext sc) {
    Log logger = LogFactory.getLog(DhccContextLoader.class);
    Properties prp = new Properties();
    Connection connection = null;
    String setupFlg = null;//from ww w .  j ava2  s  . c  o m
    String microKerne = null;
    try {
        prp.load(sc.getResourceAsStream("WEB-INF/classes/application.properties"));
        setupFlg = prp.getProperty("conf.auto.microKerne.disabled");
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    if ("true".equals(microKerne)) {
        prp = null;
        return false;
    }
    try {
        prp.load(sc.getResourceAsStream("WEB-INF/classes/hibernate.properties"));
        String url = prp.getProperty("jdbc.url");
        String driver = prp.getProperty("jdbc.driver");
        String username = prp.getProperty("jdbc.username");
        String password = prp.getProperty("jdbc.password");
        Class.forName(driver);
        connection = DriverManager.getConnection(url, username, password);
        setupFlg = "1";
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        logger.error(e.getMessage(), e);
    } catch (SQLException e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    if ("1".equals(setupFlg)) {
        prp = null;
        return false;
    }

    prp = null;
    return true;
}

From source file:io.smartspaces.spacecontroller.runtime.StandardSpaceController.java

@Override
public void startup() {
    super.startup();

    confirmUuid();/*from   ww  w .ja  v  a 2  s  .  c  o m*/

    final Log log = getSpaceEnvironment().getLog();

    spaceControllerCommunicator.onStartup(getControllerInfo());

    controllerHeartbeat = spaceControllerCommunicator.newSpaceControllerHeartbeat();
    controllerHeartbeatControl = getSpaceEnvironment().getExecutorService().scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            try {
                controllerHeartbeat.sendHeartbeat();
            } catch (Exception e) {
                log.error("Exception while trying to send a Space Controller heartbeat", e);
            }
        }
    }, heartbeatDelay, heartbeatDelay, TimeUnit.MILLISECONDS);

    dataBundleManager.startup();

    startupControllerControl();

    spaceControllerCommunicator.registerControllerWithMaster(getControllerInfo());

    startupAutostartActivities();

    startedUp = true;
}

From source file:net.sf.nmedit.nomad.core.NomadPlugin.java

private void logOsInfo(Log log) {
    String properties[] = { "java.version", "java.vendor", "java.vendor.url", "java.home",
            "java.vm.specification.version", "java.vm.specification.vendor", "java.vm.specification.name",
            "java.vm.version", "java.vm.vendor", "java.vm.name", "java.specification.version",
            "java.specification.vendor", "java.specification.name", "java.class.version", "java.class.path",
            "java.library.path", "java.io.tmpdir", "java.compiler", "java.ext.dirs", "os.name", "os.arch",
            "os.version", "file.separator", "path.separator", "line.separator", "user.name", "user.home",
            "user.dir" };

    try {//  www  .  ja  v  a2 s .c  om
        log.info("\t[System Properties]");
        for (String key : properties) {
            String value = System.getProperty(key);
            log.info("\t" + key + "=" + value);
        }
        log.info("\t[/System Properties]");
    } catch (SecurityException e) {
        log.error("logOsInfo(Log)", e);
    }
}

From source file:de.iteratec.iteraplan.businesslogic.common.LastModificationUpdateInterceptor.java

@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
    try {//from www.j  a  va 2s. c  om
        if (IteraplanProperties.getProperties()
                .propertyIsSetToTrue(IteraplanProperties.PROP_LASTMODIFICATION_LOGGING_ENABLED)) {
            Date date = new Date();
            String userName = UserContext.getCurrentUserContext().getLoginName();
            for (Object parameter : invocation.getArguments()) {
                if (parameter instanceof LastModificationEntity) {
                    LastModificationEntity lastModificationPersisentEntity = (LastModificationEntity) parameter;
                    lastModificationPersisentEntity.setLastModificationTime(date);
                    if (userName != null) {
                        lastModificationPersisentEntity.setLastModificationUser(userName);
                    }
                }
            }
            return invocation.proceed();
        }
        return invocation.proceed();
    } catch (Throwable ex) { // NOPMD - errors should be caught here as well!
        logger.error("Exception thrown in: " + invocation.getMethod().getName(), ex);
        throw ex;
    }
}

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

/**
 * Run all JUnit tests.//  ww w.j av  a2s.c  om
 *
 * @param testClasses
 *          the names of the detected JUnit classes
 * @param log
 *          logger for the test run
 *
 * @return {@code true} if all tests succeeded
 */
private boolean runJunitTests(List<Class<?>> testClasses, Log log) {
    JUnitCore junit = new JUnitCore();

    junit.addListener(new RunListener() {
        @Override
        public void testFailure(Failure failure) throws Exception {
            reportFailure(failure, log);
        }

        @Override
        public void testAssumptionFailure(Failure failure) {
            reportFailure(failure, log);
        }
    });

    log.info("Starting JUnit tests");

    boolean allSucceeded = true;
    Collections.sort(testClasses, CLASS_COMPARATOR);
    for (Class<?> testClass : testClasses) {
        try {
            Result result = junit.run(testClass);

            log.info(String.format("Ran %2d tests in %4dms: %d failed, %d ignored. (%s)", result.getRunCount(),
                    result.getRunTime(), result.getFailureCount(), result.getIgnoreCount(),
                    testClass.getName()));

            allSucceeded &= result.wasSuccessful();
        } catch (Exception e) {
            log.error(String.format("Error while running test class %s", testClass.getName()), e);
        }
    }

    log.info("JUnit tests complete");

    return allSucceeded;
}

From source file:interactivespaces.workbench.project.test.IsolatedJavaTestRunner.java

/**
 * Run all JUnit tests./*from  ww w .j av  a 2  s .co m*/
 *
 * @param classLoader
 *          the classloader for loading test classes
 * @param testClassNames
 *          the names of the detected JUnit classes
 * @param log
 *          logger for the test run
 *
 * @return {@code true} if all tests succeeded
 */
private boolean runJunitTests(URLClassLoader classLoader, List<String> testClassNames, final Log log) {
    JUnitCore junit = new JUnitCore();

    junit.addListener(new RunListener() {
        @Override
        public void testFailure(Failure failure) throws Exception {
            reportFailure(failure, log);
        }

        @Override
        public void testAssumptionFailure(Failure failure) {
            reportFailure(failure, log);
        }
    });

    log.info("Starting JUnit tests");

    boolean allSucceeded = true;
    for (String testClassName : testClassNames) {
        try {
            Class<?> testClass = classLoader.loadClass(testClassName);
            Result result = junit.run(testClass);

            log.info(String.format("Ran %2d tests in %4dms: %d failed, %d ignored. (%s)", result.getRunCount(),
                    result.getRunTime(), result.getFailureCount(), result.getIgnoreCount(), testClassName));

            allSucceeded &= result.wasSuccessful();
        } catch (Exception e) {
            log.error(String.format("Error while running test class %s", testClassName), e);
        }
    }

    log.info("JUnit tests complete");

    return allSucceeded;
}