Changeset 12765 in josm


Ignore:
Timestamp:
2017-09-07T00:37:06+02:00 (20 months ago)
Author:
wiktorn
Message:

Use tools.Logging instead of FeatureAdapter.getLogger

See: #15229

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r12620 r12765  
    2727import org.apache.commons.jcs.engine.control.CompositeCacheManager;
    2828import org.apache.commons.jcs.utils.serialization.StandardSerializer;
    29 import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    3029import org.openstreetmap.josm.Main;
    3130import org.openstreetmap.josm.data.preferences.BooleanProperty;
     
    4241 */
    4342public final class JCSCacheManager {
    44     private static final Logger LOG = FeatureAdapter.getLogger(JCSCacheManager.class.getCanonicalName());
    45 
    4643    private static volatile CompositeCacheManager cacheManager;
    4744    private static long maxObjectTTL = -1;
     
    7168        File cacheDirLockPath = new File(cacheDir, ".lock");
    7269        if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) {
    73             LOG.log(Level.WARNING, "Cannot create cache dir lock file");
     70            Logging.warn("Cannot create cache dir lock file");
    7471        }
    7572        cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock();
    7673
    7774        if (cacheDirLock == null)
    78             LOG.log(Level.WARNING, "Cannot lock cache directory. Will not use disk cache");
     75            Logging.warn("Cannot lock cache directory. Will not use disk cache");
    7976
    8077        // raising logging level gives ~500x performance gain
     
    230227        File path = new File(cachePath);
    231228        if (!path.exists() && !path.mkdirs()) {
    232             LOG.log(Level.WARNING, "Failed to create cache path: {0}", cachePath);
     229            Logging.warn("Failed to create cache path: {0}", cachePath);
    233230        } else {
    234231            ret.setDiskPath(cachePath);
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r12620 r12765  
    1616import java.util.concurrent.ThreadPoolExecutor;
    1717import java.util.concurrent.TimeUnit;
    18 import java.util.logging.Level;
    19 import java.util.logging.Logger;
    2018
    2119import org.apache.commons.jcs.access.behavior.ICacheAccess;
    2220import org.apache.commons.jcs.engine.behavior.ICacheElement;
    23 import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    2421import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult;
    2522import org.openstreetmap.josm.data.preferences.IntegerProperty;
     
    4643 */
    4744public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements ICachedLoaderJob<K> {
    48     private static final Logger LOG = FeatureAdapter.getLogger(JCSCachedTileLoaderJob.class.getCanonicalName());
    4945    protected static final long DEFAULT_EXPIRE_TIME = TimeUnit.DAYS.toMillis(7);
    5046    // Limit for the max-age value send by the server.
     
    159155        }
    160156        if (deduplicationKey == null) {
    161             LOG.log(Level.WARNING, "No url returned for: {0}, skipping", getCacheKey());
     157            Logging.warn("No url returned for: {0}, skipping", getCacheKey());
    162158            throw new IllegalArgumentException("No url returned");
    163159        }
     
    174170        if (first || force) {
    175171            // submit all jobs to separate thread, so calling thread is not blocked with IO when loading from disk
    176             LOG.log(Level.FINE, "JCS - Submitting job for execution for url: {0}", getUrlNoException());
     172            Logging.debug("JCS - Submitting job for execution for url: {0}", getUrlNoException());
    177173            downloadJobExecutor.execute(this);
    178174        }
     
    226222        final String oldName = currentThread.getName();
    227223        currentThread.setName("JCS Downloading: " + getUrlNoException());
    228         LOG.log(Level.FINE, "JCS - starting fetch of url: {0} ", getUrlNoException());
     224        Logging.debug("JCS - starting fetch of url: {0} ", getUrlNoException());
    229225        ensureCacheElement();
    230226        try {
     
    232228            if (!force && cacheElement != null && isCacheElementValid() && isObjectLoadable()) {
    233229                // we got something in cache, and it's valid, so lets return it
    234                 LOG.log(Level.FINE, "JCS - Returning object from cache: {0}", getCacheKey());
     230                Logging.debug("JCS - Returning object from cache: {0}", getCacheKey());
    235231                finishLoading(LoadResult.SUCCESS);
    236232                return;
     
    245241                    // try to get stale entry in cache
    246242                    finishLoading(LoadResult.SUCCESS);
    247                     LOG.log(Level.FINE, "JCS - found stale object in cache: {0}", getUrlNoException());
     243                    Logging.debug("JCS - found stale object in cache: {0}", getUrlNoException());
    248244                } else {
    249245                    // failed completely
     
    268264        }
    269265        if (listeners == null) {
    270             LOG.log(Level.WARNING, "Listener not found for URL: {0}. Listener not notified!", getUrlNoException());
     266            Logging.warn("Listener not found for URL: {0}. Listener not notified!", getUrlNoException());
    271267            return;
    272268        }
     
    285281            expires = Math.min(expires, attributes.getCreateTime() + EXPIRE_TIME_SERVER_LIMIT);
    286282            if (now > expires) {
    287                 LOG.log(Level.FINE, "JCS - Object {0} has expired -> valid to {1}, now is: {2}",
     283                Logging.debug("JCS - Object {0} has expired -> valid to {1}, now is: {2}",
    288284                        new Object[]{getUrlNoException(), Long.toString(expires), Long.toString(now)});
    289285                return false;
     
    292288                now - attributes.getLastModification() > DEFAULT_EXPIRE_TIME) {
    293289            // check by file modification date
    294             LOG.log(Level.FINE, "JCS - Object has expired, maximum file age reached {0}", getUrlNoException());
     290            Logging.debug("JCS - Object has expired, maximum file age reached {0}", getUrlNoException());
    295291            return false;
    296292        } else if (now - attributes.getCreateTime() > DEFAULT_EXPIRE_TIME) {
    297             LOG.log(Level.FINE, "JCS - Object has expired, maximum time since object creation reached {0}", getUrlNoException());
     293            Logging.debug("JCS - Object has expired, maximum time since object creation reached {0}", getUrlNoException());
    298294            return false;
    299295        }
     
    314310                    Boolean.TRUE.equals(useHead.get(getServerKey())) &&
    315311                    isCacheValidUsingHead()) {
    316                 LOG.log(Level.FINE, "JCS - cache entry verified using HEAD request: {0}", getUrl());
     312                Logging.debug("JCS - cache entry verified using HEAD request: {0}", getUrl());
    317313                return true;
    318314            }
    319315
    320             LOG.log(Level.FINE, "JCS - starting HttpClient GET request for URL: {0}", getUrl());
     316            Logging.debug("JCS - starting HttpClient GET request for URL: {0}", getUrl());
    321317            final HttpClient request = getRequest("GET", true);
    322318
     
    334330                // If isModifiedSince or If-None-Match has been set
    335331                // and the server answers with a HTTP 304 = "Not Modified"
    336                 LOG.log(Level.FINE, "JCS - If-Modified-Since/ETag test: local version is up to date: {0}", getUrl());
     332                Logging.debug("JCS - If-Modified-Since/ETag test: local version is up to date: {0}", getUrl());
    337333                return true;
    338334            } else if (isObjectLoadable() // we have an object in cache, but we haven't received 304 response code
     
    344340                // for further requests - use HEAD
    345341                String serverKey = getServerKey();
    346                 LOG.log(Level.INFO, "JCS - Host: {0} found not to return 304 codes for If-Modified-Since or If-None-Match headers",
     342                Logging.info("JCS - Host: {0} found not to return 304 codes for If-Modified-Since or If-None-Match headers",
    347343                        serverKey);
    348344                useHead.put(serverKey, Boolean.TRUE);
     
    370366                    cacheData = createCacheEntry(raw);
    371367                    cache.put(getCacheKey(), cacheData, attributes);
    372                     LOG.log(Level.FINE, "JCS - downloaded key: {0}, length: {1}, url: {2}",
     368                    Logging.debug("JCS - downloaded key: {0}, length: {1}, url: {2}",
    373369                            new Object[] {getCacheKey(), raw.length, getUrl()});
    374370                    return true;
     
    376372                    cacheData = createCacheEntry(new byte[]{});
    377373                    cache.put(getCacheKey(), cacheData, attributes);
    378                     LOG.log(Level.FINE, "JCS - Caching empty object {0}", getUrl());
     374                    Logging.debug("JCS - Caching empty object {0}", getUrl());
    379375                    return true;
    380376                } else {
    381                     LOG.log(Level.FINE, "JCS - failure during load - reponse is not loadable nor cached as empty");
     377                    Logging.debug("JCS - failure during load - reponse is not loadable nor cached as empty");
    382378                    return false;
    383379                }
    384380            }
    385381        } catch (FileNotFoundException e) {
    386             LOG.log(Level.FINE, "JCS - Caching empty object as server returned 404 for: {0}", getUrlNoException());
     382            Logging.debug("JCS - Caching empty object as server returned 404 for: {0}", getUrlNoException());
    387383            attributes.setResponseCode(404);
    388384            attributes.setError(e);
     
    394390            return doCache;
    395391        } catch (IOException e) {
    396             LOG.log(Level.FINE, "JCS - IOExecption during communication with server for: {0}", getUrlNoException());
     392            Logging.debug("JCS - IOExecption during communication with server for: {0}", getUrlNoException());
    397393            if (isObjectLoadable()) {
    398394                return true;
     
    405401        } catch (InterruptedException e) {
    406402            attributes.setError(e);
    407             LOG.log(Level.WARNING, "JCS - Exception during download {0}", getUrlNoException());
    408             Logging.warn(e);
     403            Logging.logWithStackTrace(Logging.LEVEL_WARN, e, "JCS - Exception during download {0}", getUrlNoException());
    409404            Thread.currentThread().interrupt();
    410405        }
    411         LOG.log(Level.WARNING, "JCS - Silent failure during download: {0}", getUrlNoException());
     406        Logging.warn("JCS - Silent failure during download: {0}", getUrlNoException());
    412407        return false;
    413408    }
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r12620 r12765  
    1717import java.util.concurrent.ThreadPoolExecutor;
    1818import java.util.concurrent.TimeUnit;
    19 import java.util.logging.Level;
    20 import java.util.logging.Logger;
    2119
    2220import org.apache.commons.jcs.access.behavior.ICacheAccess;
    23 import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    2421import org.openstreetmap.gui.jmapviewer.Tile;
    2522import org.openstreetmap.gui.jmapviewer.interfaces.TileJob;
     
    4340 */
    4441public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, BufferedImageCacheEntry> implements TileJob, ICachedLoaderListener {
    45     private static final Logger LOG = FeatureAdapter.getLogger(TMSCachedTileLoaderJob.class.getCanonicalName());
    4642    private static final LongProperty MAXIMUM_EXPIRES = new LongProperty("imagery.generic.maximum_expires", TimeUnit.DAYS.toMillis(30));
    4743    private static final LongProperty MINIMUM_EXPIRES = new LongProperty("imagery.generic.minimum_expires", TimeUnit.HOURS.toMillis(1));
     
    123119                return content.length > 0 || cacheData.getImage() != null || isNoTileAtZoom();
    124120            } catch (IOException e) {
    125                 LOG.log(Level.WARNING, "JCS TMS - error loading from cache for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    126                 Logging.warn(e);
     121                Logging.logWithStackTrace(Logging.LEVEL_WARN, e, "JCS TMS - error loading from cache for tile {0}: {1}",
     122                        new Object[] {tile.getKey(), e.getMessage()}
     123                        );
    127124            }
    128125        }
     
    208205            }
    209206        } catch (IOException e) {
    210             LOG.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
     207            Logging.warn("JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    211208            tile.setError(e);
    212209            tile.setLoaded(false);
     
    259256    private boolean handleNoTileAtZoom() {
    260257        if (isNoTileAtZoom()) {
    261             LOG.log(Level.FINE, "JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile);
     258            Logging.debug("JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile);
    262259            tile.setError("No tile at this zoom level");
    263260            tile.putValue("tile-info", "no-tile");
     
    269266    private boolean isNoTileAtZoom() {
    270267        if (attributes == null) {
    271             LOG.warning("Cache attributes are null");
     268            Logging.warn("Cache attributes are null");
    272269        }
    273270        return attributes != null && attributes.isNoTileAtZoom();
  • trunk/src/org/openstreetmap/josm/tools/Logging.java

    r12621 r12765  
    271271    }
    272272
     273    /**
     274     * Logs a throwable that happened. Adds the stack trace to the log.
     275     * @param level The level.
     276     * @param t The throwable that should be logged.
     277     * @param pattern The formatted message to print.
     278     * @param args The objects to insert into format string
     279     * @see #logWithStackTrace(Level, Throwable)
     280     */
     281    public static void logWithStackTrace(Level level, Throwable t, String pattern, Object... args) {
     282        logPrivate(level, () -> getErrorLogWithStack(MessageFormat.format(pattern,  args), t));
     283    }
     284
     285
    273286    private static void logPrivate(Level level, String pattern, Object... args) {
    274287        logPrivate(level, () -> MessageFormat.format(pattern, args));
Note: See TracChangeset for help on using the changeset viewer.