improve logging

This commit is contained in:
Sebastian Sdorra
2011-02-12 10:58:58 +01:00
parent dbb757414b
commit 106cd6717c
2 changed files with 32 additions and 2 deletions

View File

@@ -37,6 +37,9 @@ package sonia.scm.cache;
import net.sf.ehcache.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Sebastian Sdorra
@@ -47,15 +50,22 @@ import net.sf.ehcache.Element;
public class EhCache<K, V> implements Cache<K, V>
{
/** the logger for EhCache */
private static final Logger logger = LoggerFactory.getLogger(EhCache.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs ...
*
*
* @param cache
* @param name
*/
public EhCache(net.sf.ehcache.Cache cache)
public EhCache(net.sf.ehcache.Cache cache, String name)
{
this.cache = cache;
this.name = name;
}
//~--- methods --------------------------------------------------------------
@@ -67,6 +77,11 @@ public class EhCache<K, V> implements Cache<K, V>
@Override
public void clear()
{
if (logger.isDebugEnabled())
{
logger.debug("clear cache {}", name);
}
cache.removeAll();
}
@@ -139,4 +154,7 @@ public class EhCache<K, V> implements Cache<K, V>
/** Field description */
private net.sf.ehcache.Cache cache;
/** Field description */
private String name;
}

View File

@@ -37,6 +37,9 @@ package sonia.scm.cache;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Sebastian Sdorra
@@ -48,6 +51,10 @@ public class EhCacheManager implements CacheManager
/** Field description */
public static final String CONFIG = "/config/ehcache.xml";
/** the logger for EhCacheManager */
private static final Logger logger =
LoggerFactory.getLogger(EhCacheManager.class);
//~--- constructors ---------------------------------------------------------
/**
@@ -77,7 +84,12 @@ public class EhCacheManager implements CacheManager
@Override
public <K, V> Cache<K, V> getCache(Class<K> key, Class<V> value, String name)
{
return new EhCache<K, V>(cacheManager.getCache(name));
if (logger.isInfoEnabled())
{
logger.info("create new cache {}", name);
}
return new EhCache<K, V>(cacheManager.getCache(name), name);
}
//~--- fields ---------------------------------------------------------------