diff --git a/pom.xml b/pom.xml index 100cf50..3f6aeaa 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,21 @@ lucene-core 3.0.0 + + org.slf4j + slf4j-api + 1.5.10 + + + org.slf4j + slf4j-log4j12 + 1.5.10 + + + org.slf4j + jul-to-slf4j + 1.5.10 + diff --git a/src/main/java/org/forkalsrud/album/exif/DirectoryEntry.java b/src/main/java/org/forkalsrud/album/exif/DirectoryEntry.java index c653ff2..2acf1a0 100644 --- a/src/main/java/org/forkalsrud/album/exif/DirectoryEntry.java +++ b/src/main/java/org/forkalsrud/album/exif/DirectoryEntry.java @@ -6,7 +6,6 @@ package org.forkalsrud.album.exif; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -42,6 +41,8 @@ import com.drew.metadata.jpeg.JpegDirectory; */ public class DirectoryEntry extends Entry { + private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DirectoryEntry.class); + final static String CACHE_FILE = "cache.properties"; final static String OVERRIDE_FILE = "album.properties"; @@ -151,7 +152,7 @@ public class DirectoryEntry extends Entry { long end = System.currentTimeMillis(); props.setTimestamp(end); db.store(file.getAbsolutePath(), props); - System.out.println("Time to generate properties for " + file.getPath() + ": " + (end - start)/1000d + " s"); + log.info("Time to generate properties for " + file.getPath() + ": " + (end - start)/1000d + " s"); return props; } diff --git a/src/main/java/org/forkalsrud/album/web/AlbumServlet.java b/src/main/java/org/forkalsrud/album/web/AlbumServlet.java index 6ce401c..59637c0 100644 --- a/src/main/java/org/forkalsrud/album/web/AlbumServlet.java +++ b/src/main/java/org/forkalsrud/album/web/AlbumServlet.java @@ -8,6 +8,7 @@ import java.util.Calendar; import java.util.Date; import java.util.Properties; import java.util.logging.Handler; +import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -31,8 +32,8 @@ import com.sleepycat.je.EnvironmentConfig; public class AlbumServlet extends HttpServlet { - - + private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(AlbumServlet.class); + /* static void addDummyLoggerFor(String... names) { for (String name : names) try { @@ -74,7 +75,7 @@ public class AlbumServlet "com.sleepycat.je.cleaner.FileProcessor", "com.sleepycat.je.recovery.RecoveryManager"); } - + */ File base; String basePrefix; PictureScaler pictureScaler; @@ -103,7 +104,7 @@ public class AlbumServlet } log4jInit("/log4j.properties"); - System.out.println("in init of Album"); + log.info("in init of Album"); base = new File(props.getProperty("base", "photos")).getAbsoluteFile(); basePrefix = "/" + base.getName(); @@ -135,7 +136,7 @@ public class AlbumServlet @Override public void destroy() { - System.out.println("Shutting down Album"); + log.info("Shutting down Album"); dirDb.destroy(); thumbDb.destroy(); environment.close(); @@ -239,14 +240,14 @@ public class AlbumServlet if (notModified(req, file)) { res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000L)); // 30 days - System.out.println(file.getName() + " not modified (based on date)"); + log.info(file.getName() + " not modified (based on date)"); return; } String fileEtag = thumbnail.getEtag() + "-" + size; if (etagMatches(req, fileEtag)) { res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000L)); // 30 days - System.out.println(file.getName() + " not modified (based on etag)"); + log.info(file.getName() + " not modified (based on etag)"); return; } @@ -255,16 +256,16 @@ public class AlbumServlet CachedImage cimg = thumbDb.load(key); if (cimg != null) { if (cimg.lastModified == file.lastModified()) { - System.out.println("cache hit on " + key); + log.info("cache hit on " + key); } else { - System.out.println(" " + key + " has changed so cache entry wil be refreshed"); + log.info(" " + key + " has changed so cache entry wil be refreshed"); cimg = null; } } if (cimg == null) { cimg = pictureScaler.scalePicture(file, thumbnail, size); thumbDb.store(key, cimg); - System.out.println(" " + key + " added to the cache with size " + cimg.bits.length + " -- now " + thumbDb.size() + " entries"); + log.info(" " + key + " added to the cache with size " + cimg.bits.length + " -- now " + thumbDb.size() + " entries"); } res.setStatus(HttpServletResponse.SC_OK); res.setDateHeader("Last-Modified", file.lastModified()); diff --git a/src/main/java/org/forkalsrud/album/web/PictureScaler.java b/src/main/java/org/forkalsrud/album/web/PictureScaler.java index 88c8424..616f04e 100644 --- a/src/main/java/org/forkalsrud/album/web/PictureScaler.java +++ b/src/main/java/org/forkalsrud/album/web/PictureScaler.java @@ -31,6 +31,8 @@ import org.forkalsrud.album.exif.Thumbnail; public class PictureScaler { + private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PictureScaler.class); + ExecutorService executor; BlockingQueue queue; HashMap outstandingRequests; @@ -125,8 +127,7 @@ public class PictureScaler { e.printStackTrace(); return null; } catch (OutOfMemoryError e) { - System.out.println(file); - e.printStackTrace(); + log.error(file.getPath(), e); return null; } catch (ExecutionException e) { throw new RuntimeException(e);