Skip to content

Commit

Permalink
WatchImporter: Switch to slf4j logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ato committed Oct 10, 2023
1 parent 85f27bd commit 68df153
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ui/src/bamboo/task/WatchImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import bamboo.core.*;
import bamboo.crawl.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -10,7 +12,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import static java.nio.file.StandardWatchEventKinds.*;

Expand All @@ -19,7 +20,7 @@
* they're closed (renamed to *.warc.gz) finish importing them.
*/
public class WatchImporter implements Runnable {
final static Logger log = Logger.getLogger(WatchImporter.class.getName());
final static Logger log = LoggerFactory.getLogger(WatchImporter.class);
final Map<Path,Config.Watch> watches = new HashMap<>();
final Warcs warcs;
final Crawls crawls;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void run() {
for (WatchKey key = watcher.take(); key.isValid(); key = watcher.take()) {
Config.Watch watch = watches.get(key.watchable());
if (watch == null) {
log.warning("Ignoring unexpected watch key " + key.watchable());
log.warn("Ignoring unexpected watch key " + key.watchable());
continue;
}
for (WatchEvent<?> event : key.pollEvents()) {
Expand All @@ -61,7 +62,7 @@ public void run() {
}

Path path = watch.dir.resolve((Path) event.context());
log.finest("saw event " + path);
log.trace("saw event " + path);

if (!Files.exists(path)) {
/*
Expand Down Expand Up @@ -95,7 +96,7 @@ public void run() {
* Incrementally index any new records.
*/
void handleOpenWarc(Config.Watch watch, Path path) throws IOException {
log.finest("handleOpenWarc(" + path + ")");
log.trace("handleOpenWarc(" + path + ")");
long warcId, prevSize;
long currentSize = Files.size(path);
String filename = path.getFileName().toString().replaceFirst(".open$", "");
Expand All @@ -122,7 +123,7 @@ void handleOpenWarc(Config.Watch watch, Path path) throws IOException {
* Move the WARC into the crawl's archival directory and finalise the db record.
*/
private void handleClosedWarc(Config.Watch watch, Path path) throws IOException {
log.finest("handleClosedWarc(" + path + ")");
log.trace("handleClosedWarc(" + path + ")");

long size = Files.size(path);
if (size == 0) {
Expand All @@ -133,7 +134,7 @@ private void handleClosedWarc(Config.Watch watch, Path path) throws IOException
try (FileChannel channel = FileChannel.open(path, StandardOpenOption.WRITE)) {
var lock = channel.tryLock();
if (lock == null) {
log.finest("WARC has file lock, treating as still open: " + path);
log.trace("WARC has file lock, treating as still open: " + path);
handleOpenWarc(watch, path);
return;
}
Expand Down Expand Up @@ -172,6 +173,7 @@ private Path moveWarcToCrawlDir(Path path, Crawl crawl) throws IOException {
*/
private void scanForChanges() throws IOException {
for (Config.Watch watch : watches.values()) {
log.info("Scanning for changes: {}", watch.dir);
try (DirectoryStream<Path> stream = Files.newDirectoryStream(watch.dir)) {
for (Path entry : stream) {
if (entry.toString().endsWith(".warc.gz.open")) {
Expand Down

0 comments on commit 68df153

Please sign in to comment.