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:com.flexive.shared.exceptions.FxApplicationException.java

/**
 * Log a message at a given level (or error if no level given)
 *
 * @param log     Log to use/*from  ww w  . j a  va2s.  co m*/
 * @param message message to LOG
 * @param level   log4j level to apply
 */
private void logMessage(Log log, String message, LogLevel level) {
    this.messageLogged = true;
    if (FxContext.get() != null && FxContext.get().isTestDivision())
        return; //dont log exception traces during automated tests
    final Throwable cause = getCause() != null ? getCause() : this;
    if (level == null)
        log.error(message, cause);
    else {
        switch (level) {
        case DEBUG:
            if (log.isDebugEnabled())
                log.debug(message);
            break;
        case ERROR:
            if (log.isErrorEnabled())
                log.error(message, cause);
            break;
        case FATAL:
            if (log.isFatalEnabled())
                log.fatal(message, cause);
            break;
        case INFO:
            if (log.isInfoEnabled())
                log.info(message);
            break;
        //                case Level.WARN_INT:
        default:
            if (log.isWarnEnabled())
                log.warn(message);
        }
    }
}

From source file:com.lolay.citygrid.ads.custom.CustomAdsIntegration.java

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

    CustomAdsClient pfpProxy = new ClientFactory(baseUrl).getCustomAds();

    CustomAdsInvoker pfp = CustomAdsInvoker.builder().what("restaurant").where("90069").publisher("citysearch")
            .build();/*from   www  .  j  a  va  2s . com*/
    CustomAdsResults results = null;
    try {
        long start = System.currentTimeMillis();
        results = pfp.where(pfpProxy);
        long end = System.currentTimeMillis();
        log.trace(String.format("PFP took %s ms", end - start));
    } catch (WebApplicationException e) {
        log.error(e.getResponse(), e);
        fail();
    }

    assertNotNull(results);
    assertNotNull(results.getAds());
    assertEquals(10, results.getAds().size());
    for (CustomAd ad : results.getAds()) {
        assertNotNull(ad.getType());
        assertNotNull(ad.getAdDestinationUrl());

        if (ad.getListingId() != null && ad.getListingId() != 0) {
            assertNotNull(ad.getId());
            assertNotNull(ad.getImpressionId());
            assertNotNull(ad.getName());
            assertNotNull(ad.getLatitude());
            assertNotNull(ad.getLongitude());
            assertNotNull(ad.getGrossPpe());
        } else {
            assertNotNull(ad.getTagline());
            assertNotNull(ad.getDescription());
        }
    }

}

From source file:com.lolay.citygrid.ads.custom.CustomAdsIntegration.java

public void disabledtestBanner() throws Exception {
    final Log log = testBannerLog;
    log.trace("ENTER");

    CustomAdsClient pfpProxy = new ClientFactory(baseUrl).getCustomAds();

    CustomAdsInvoker pfp = CustomAdsInvoker.builder().what("restaurant").where("90069").publisher("citysearch")
            .rotation(true).build();/*from w  w  w .j  a v  a 2s .  com*/
    BannerResults results = null;
    try {
        long start = System.currentTimeMillis();
        results = pfp.banner(pfpProxy);
        long end = System.currentTimeMillis();
        log.trace(String.format("PFP Banner took %s ms", end - start));
    } catch (WebApplicationException e) {
        log.error(e.getResponse(), e);
        fail();
    }

    assertNotNull(results);
    assertNotNull(results.getAds());
    assertEquals(10, results.getAds().size());
    for (BannerAd ad : results.getAds()) {
        assertNotNull(ad.getId());
        assertNotNull(ad.getListingId());
        assertNotNull(ad.getAdDestinationUrl());
        assertNotNull(ad.getAdImageUrl());
    }
}

From source file:com.ayovel.nian.exception.XLog.java

private void log(Level level, int loggerMask, String msgTemplate, Object... params) {
    loggerMask |= STD;/*  w  ww  .j a v  a 2s.  com*/
    if (isEnabled(level, loggerMask)) {
        String prefix = getMsgPrefix() != null ? getMsgPrefix() : Info.get().getPrefix();
        prefix = (prefix != null && prefix.length() > 0) ? prefix + " " : "";

        String msg = prefix + format(msgTemplate, params);
        Throwable throwable = getCause(params);

        for (int i = 0; i < LOGGER_MASKS.length; i++) {
            if (isEnabled(level, loggerMask & LOGGER_MASKS[i])) {
                Log log = loggers[i];
                switch (level) {
                case FATAL:
                    log.fatal(msg, throwable);
                    break;
                case ERROR:
                    log.error(msg, throwable);
                    break;
                case INFO:
                    log.info(msg, throwable);
                    break;
                case WARN:
                    log.warn(msg, throwable);
                    break;
                case DEBUG:
                    log.debug(msg, throwable);
                    break;
                case TRACE:
                    log.trace(msg, throwable);
                    break;
                }
            }
        }
    }
}

From source file:arena.utils.FileUtils.java

public static void gzip(File input, File outFile) {
    Log log = LogFactory.getLog(FileUtils.class);
    InputStream inStream = null;//from  w  w  w .  jav a  2  s  .  co  m
    OutputStream outStream = null;
    GZIPOutputStream gzip = null;
    try {
        long inFileLengthKB = input.length() / 1024L;

        // Open the out file
        if (outFile == null) {
            outFile = new File(input.getParentFile(), input.getName() + ".gz");
        }
        inStream = new FileInputStream(input);
        outStream = new FileOutputStream(outFile, true);
        gzip = new GZIPOutputStream(outStream);

        // Iterate through in buffers and write out to the gzipped output stream
        byte buffer[] = new byte[102400]; // 100k buffer
        int read = 0;
        long readSoFar = 0;
        while ((read = inStream.read(buffer)) != -1) {
            readSoFar += read;
            gzip.write(buffer, 0, read);
            log.debug("Gzipped " + (readSoFar / 1024L) + "KB / " + inFileLengthKB + "KB of logfile "
                    + input.getName());
        }

        // Close the streams
        inStream.close();
        inStream = null;
        gzip.close();
        gzip = null;
        outStream.close();
        outStream = null;

        // Delete the old file
        input.delete();
        log.debug("Gzip of logfile " + input.getName() + " complete");
    } catch (IOException err) {
        // Delete the gzip file
        log.error("Error during gzip of logfile " + input, err);
    } finally {
        if (inStream != null) {
            try {
                inStream.close();
            } catch (IOException err2) {
            }
        }
        if (gzip != null) {
            try {
                gzip.close();
            } catch (IOException err2) {
            }
        }
        if (outStream != null) {
            try {
                outStream.close();
            } catch (IOException err2) {
            }
        }
    }
}

From source file:com.lolay.citygrid.ads.tracking.TrackingIntegration.java

public void testImpression() throws Exception {
    Log log = testImpressionLog;

    log.trace("ENTER");

    TrackingClient client = new ClientFactory(baseUrl).getTracking();
    TrackingInvoker invoker = TrackingInvoker.builder().listingId(1).referenceId(1).impressionId("1")
            .actionTarget(TrackingActionTarget.LISTING_PROFILE).mobileType("junit")
            .muid("1234567890abcdef1234567890abcdef12345678").ua("Integratin/1.0").publisher("4214549098")
            .placement("junit").build();

    try {/*from w w w . java  2  s .co  m*/
        long start = System.currentTimeMillis();
        invoker.impression(client);
        long end = System.currentTimeMillis();
        log.trace(String.format("Impression tracking took %s ms", end - start));
    } catch (InvokerException e) {
        log.error(e.getErrorCodes(), e);
        fail();
    }
}

From source file:com.lolay.citygrid.ads.custom.CustomAdsIntegration.java

public void testLatLon() throws Exception {
    final Log log = testLatLonLog;
    log.trace("ENTER");

    CustomAdsClient pfpProxy = new ClientFactory(baseUrl).getCustomAds();

    CustomAdsInvoker pfp = CustomAdsInvoker.builder().what("restaurant").latitude(34.0522222D)
            .longitude(-118.2427778D).radius(50).publisher("citysearch").build();
    CustomAdsResults results = null;//from  ww  w.j a  v  a 2 s  .  co  m
    try {
        long start = System.currentTimeMillis();
        results = pfp.latlon(pfpProxy);
        long end = System.currentTimeMillis();
        log.trace(String.format("PFP location took %s ms", end - start));
    } catch (WebApplicationException e) {
        log.error(e.getResponse(), e);
        fail();
    }

    assertNotNull(results);
    assertNotNull(results.getAds());
    assertEquals(10, results.getAds().size());
    for (CustomAd ad : results.getAds()) {
        assertNotNull(ad.getType());
        assertNotNull(ad.getAdDestinationUrl());

        if (ad.getListingId() != null) {
            assertNotNull(ad.getId());
            assertNotNull(ad.getImpressionId());
            assertNotNull(ad.getName());
            assertNotNull(ad.getLatitude());
            assertNotNull(ad.getLongitude());
            assertNotNull(ad.getGrossPpe());
        } else {
            assertNotNull(ad.getTagline());
            assertNotNull(ad.getDescription());
        }
    }

}

From source file:com.amazon.carbonado.repo.replicated.ReplicationTrigger.java

/**
 * Runs a repair in a background thread. This is done for two reasons: It
 * allows repair to not be hindered by locks acquired by transactions and
 * repairs don't get rolled back when culprit exception is thrown. Culprit
 * may be UniqueConstraintException or OptimisticLockException.
 *///from w w  w .j a v a2s .  c om
private void repair(S replica) throws PersistException {
    replica = (S) replica.copy();
    S master = mMasterStorage.prepare();
    // Must copy more than just primary key properties to master since
    // replica object might only have alternate keys.
    replica.copyAllProperties(master);

    try {
        if (replica.tryLoad()) {
            if (master.tryLoad()) {
                if (replica.equalProperties(master)) {
                    // Both are equal -- no repair needed.
                    return;
                }
            }
        } else {
            if (!master.tryLoad()) {
                // Both are missing -- no repair needed.
                return;
            }
        }
    } catch (IllegalStateException e) {
        // Can be caused by not fully defining the primary key on the
        // replica, but an alternate key is. The insert will fail anyhow,
        // so don't try to repair.
        return;
    } catch (FetchException e) {
        throw e.toPersistException();
    }

    final S finalReplica = replica;
    final S finalMaster = master;

    RepairExecutor.execute(new Runnable() {
        public void run() {
            try {
                Transaction txn = mRepository.enterTransaction();
                try {
                    txn.setForUpdate(true);
                    if (finalReplica.tryLoad()) {
                        if (finalMaster.tryLoad()) {
                            resyncEntries(null, finalReplica, finalMaster, false);
                        } else {
                            resyncEntries(null, finalReplica, null, false);
                        }
                    } else if (finalMaster.tryLoad()) {
                        resyncEntries(null, null, finalMaster, false);
                    }
                    txn.commit();
                } finally {
                    txn.exit();
                }
            } catch (FetchException fe) {
                Log log = LogFactory.getLog(ReplicatedRepository.class);
                log.warn("Unable to check if repair is required for " + finalReplica.toStringKeyOnly(), fe);
            } catch (PersistException pe) {
                Log log = LogFactory.getLog(ReplicatedRepository.class);
                log.error("Unable to repair entry " + finalReplica.toStringKeyOnly(), pe);
            }
        }
    });
}

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 {// www  .j  a  va2  s . 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: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;/* w ww .ja  v a 2s  .  c o m*/
    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());
        }
    }
}