introduce slf4j
This commit is contained in:
parent
a87708541e
commit
6dd333992e
4 changed files with 32 additions and 14 deletions
15
pom.xml
15
pom.xml
|
|
@ -135,6 +135,21 @@
|
|||
<artifactId>lucene-core</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</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>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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<PictureRequest> queue;
|
||||
HashMap<String, PictureRequest> 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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue