feat(mon_dir): added Logger class
This commit is contained in:
parent
bea46175be
commit
9188c9d753
|
@ -83,4 +83,14 @@
|
|||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!--required for Logger class-->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
package de.swingbe.mon_dir;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class Main {
|
||||
private static final String FOLDER="/opt/npm";
|
||||
public final static Logger LOG = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
private static final String FOLDER = "/opt/npm";
|
||||
|
||||
public static void main(String[] args) throws IOException,
|
||||
InterruptedException {
|
||||
|
@ -16,7 +21,8 @@ public class Main {
|
|||
|
||||
//register a Path instance for events using a WatchService instance
|
||||
folder.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,
|
||||
StandardWatchEventKinds.ENTRY_MODIFY);
|
||||
StandardWatchEventKinds.ENTRY_MODIFY,
|
||||
StandardWatchEventKinds.ENTRY_DELETE);
|
||||
|
||||
boolean valid = true;
|
||||
do {
|
||||
|
@ -27,16 +33,16 @@ public class Main {
|
|||
|
||||
if (StandardWatchEventKinds.ENTRY_CREATE.equals(event.kind())) {
|
||||
String fileName = event.context().toString();
|
||||
System.out.println("File created:" + fileName);
|
||||
LOG.debug("File created: " + fileName);
|
||||
} else if (StandardWatchEventKinds.ENTRY_MODIFY.equals(event.kind())) {
|
||||
Path context = (Path) event.context();
|
||||
String fileName = context.toString();
|
||||
System.out.println("File modified:" + fileName);
|
||||
LOG.debug("File modified: " + fileName);
|
||||
} else if (StandardWatchEventKinds.ENTRY_DELETE.equals(event.kind())) {
|
||||
String fileName = event.context().toString();
|
||||
System.out.println("File deleted:" + fileName);
|
||||
LOG.debug("File deleted: " + fileName);
|
||||
} else {
|
||||
System.out.println("Event unknown");
|
||||
LOG.warn("Event unknown");
|
||||
}
|
||||
valid = watchKey.reset();
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<RollingFile name="rollingFile"
|
||||
fileName="sizeRolling.log"
|
||||
filePattern="sizeRolling-%d{yyyy-MM-dd}.log"
|
||||
ignoreExceptions="false"
|
||||
>
|
||||
<PatternLayout>
|
||||
<Pattern>[%-5p] %d{yyyy-MM-dd HH:mm:ss.SSS} %c{1} %m%n</Pattern>
|
||||
</PatternLayout>
|
||||
<Policies>
|
||||
<SizeBasedTriggeringPolicy size="3MB"/>
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="5"/>
|
||||
</RollingFile>
|
||||
|
||||
<Console name="console" target="SYSTEM_OUT">
|
||||
<PatternLayout
|
||||
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} %c{1} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Logger name="de.swingbe" level="all" additivity="true">
|
||||
<appender-ref ref="rollingFile" level="debug"/>
|
||||
</Logger>
|
||||
<Root level="debug" additivity="false">
|
||||
<appender-ref ref="console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
|
||||
</Configuration>
|
Loading…
Reference in New Issue