introduce slf4j

This commit is contained in:
Knut Forkalsrud 2010-05-22 12:31:34 -07:00
parent a87708541e
commit 6dd333992e
4 changed files with 32 additions and 14 deletions

15
pom.xml
View file

@ -135,6 +135,21 @@
<artifactId>lucene-core</artifactId> <artifactId>lucene-core</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.5.10</version>
</dependency>
</dependencies> </dependencies>
<repositories> <repositories>
<repository> <repository>

View file

@ -6,7 +6,6 @@ package org.forkalsrud.album.exif;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat; import java.text.NumberFormat;
@ -42,6 +41,8 @@ import com.drew.metadata.jpeg.JpegDirectory;
*/ */
public class DirectoryEntry extends Entry { 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 CACHE_FILE = "cache.properties";
final static String OVERRIDE_FILE = "album.properties"; final static String OVERRIDE_FILE = "album.properties";
@ -151,7 +152,7 @@ public class DirectoryEntry extends Entry {
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
props.setTimestamp(end); props.setTimestamp(end);
db.store(file.getAbsolutePath(), props); 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; return props;
} }

View file

@ -8,6 +8,7 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -31,8 +32,8 @@ import com.sleepycat.je.EnvironmentConfig;
public class AlbumServlet public class AlbumServlet
extends HttpServlet extends HttpServlet
{ {
private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(AlbumServlet.class);
/*
static void addDummyLoggerFor(String... names) { static void addDummyLoggerFor(String... names) {
for (String name : names) for (String name : names)
try { try {
@ -74,7 +75,7 @@ public class AlbumServlet
"com.sleepycat.je.cleaner.FileProcessor", "com.sleepycat.je.cleaner.FileProcessor",
"com.sleepycat.je.recovery.RecoveryManager"); "com.sleepycat.je.recovery.RecoveryManager");
} }
*/
File base; File base;
String basePrefix; String basePrefix;
PictureScaler pictureScaler; PictureScaler pictureScaler;
@ -103,7 +104,7 @@ public class AlbumServlet
} }
log4jInit("/log4j.properties"); log4jInit("/log4j.properties");
System.out.println("in init of Album"); log.info("in init of Album");
base = new File(props.getProperty("base", "photos")).getAbsoluteFile(); base = new File(props.getProperty("base", "photos")).getAbsoluteFile();
basePrefix = "/" + base.getName(); basePrefix = "/" + base.getName();
@ -135,7 +136,7 @@ public class AlbumServlet
@Override @Override
public void destroy() { public void destroy() {
System.out.println("Shutting down Album"); log.info("Shutting down Album");
dirDb.destroy(); dirDb.destroy();
thumbDb.destroy(); thumbDb.destroy();
environment.close(); environment.close();
@ -239,14 +240,14 @@ public class AlbumServlet
if (notModified(req, file)) { if (notModified(req, file)) {
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000L)); // 30 days 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; return;
} }
String fileEtag = thumbnail.getEtag() + "-" + size; String fileEtag = thumbnail.getEtag() + "-" + size;
if (etagMatches(req, fileEtag)) { if (etagMatches(req, fileEtag)) {
res.setStatus(HttpServletResponse.SC_NOT_MODIFIED); res.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
res.setDateHeader("Expires", System.currentTimeMillis() + (30 * 24 * 3600 * 1000L)); // 30 days 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; return;
} }
@ -255,16 +256,16 @@ public class AlbumServlet
CachedImage cimg = thumbDb.load(key); CachedImage cimg = thumbDb.load(key);
if (cimg != null) { if (cimg != null) {
if (cimg.lastModified == file.lastModified()) { if (cimg.lastModified == file.lastModified()) {
System.out.println("cache hit on " + key); log.info("cache hit on " + key);
} else { } 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; cimg = null;
} }
} }
if (cimg == null) { if (cimg == null) {
cimg = pictureScaler.scalePicture(file, thumbnail, size); cimg = pictureScaler.scalePicture(file, thumbnail, size);
thumbDb.store(key, cimg); 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.setStatus(HttpServletResponse.SC_OK);
res.setDateHeader("Last-Modified", file.lastModified()); res.setDateHeader("Last-Modified", file.lastModified());

View file

@ -31,6 +31,8 @@ import org.forkalsrud.album.exif.Thumbnail;
public class PictureScaler { public class PictureScaler {
private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(PictureScaler.class);
ExecutorService executor; ExecutorService executor;
BlockingQueue<PictureRequest> queue; BlockingQueue<PictureRequest> queue;
HashMap<String, PictureRequest> outstandingRequests; HashMap<String, PictureRequest> outstandingRequests;
@ -125,8 +127,7 @@ public class PictureScaler {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
System.out.println(file); log.error(file.getPath(), e);
e.printStackTrace();
return null; return null;
} catch (ExecutionException e) { } catch (ExecutionException e) {
throw new RuntimeException(e); throw new RuntimeException(e);