Commit cc11173e authored by Tatyana's avatar Tatyana 👽

log4j2 added

log4j2 attached to FileMonitor
parent ba16edd9
package application.util;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
......@@ -19,6 +22,8 @@ public class FileMonitor extends Thread {
private boolean finish = false;
private final boolean recursive;
static Logger logger = LogManager.getLogger(FileMonitor.class);
@SuppressWarnings("unchecked")
private static <T> WatchEvent<T> cast(WatchEvent<?> event) {
return (WatchEvent<T>) event;
......@@ -43,10 +48,10 @@ public class FileMonitor extends Thread {
if (trace) {
Path prev = keys.get(key);
if (prev == null) {
System.out.format("register: %s\n", dir);
logger.info(String.format("register: %s\n", dir));
} else {
if (!dir.equals(prev)) {
System.out.format("update: %s -> %s\n", prev, dir);
logger.info(String.format("update: %s -> %s\n", prev, dir));
}
}
}
......@@ -91,7 +96,7 @@ public class FileMonitor extends Thread {
Path dir = keys.get(key);
if (dir == null) {
System.err.println("WatchKey not recognized!!");
logger.error("WatchKey not recognized!!");
continue;
}
......@@ -111,7 +116,7 @@ public class FileMonitor extends Thread {
fileSearcher.addFile(child.toAbsolutePath().toFile());
// print out event
System.out.format("%s: %s\n", event.kind().name(), child);
logger.info(String.format("%s: %s\n", event.kind().name(), child));
if (event.kind() == ENTRY_CREATE)
fileSearcher.addFile(child.toAbsolutePath().toFile());
if (event.kind() == ENTRY_DELETE)
......
appenders = console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%-5level] %d{HH:mm} %c{1} - %msg
rootLogger.level = info
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment