Skip to content

Commit

Permalink
update file montior pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
wtt40122 committed Oct 10, 2023
1 parent 58d0052 commit 1432d97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public void reg(String path, Predicate<String> predicate) throws IOException, In
WatchKey key = watchService.take();
for (WatchEvent<?> event : key.pollEvents()) {
Path modifiedFile = (Path) event.context();
if (!predicate.test(modifiedFile.getFileName().toString()) || modifiedFile.getFileName().toString().startsWith(".")) {
String filePath = String.format("%s%s", path, modifiedFile.getFileName().toString());
if (!predicate.test(filePath) || modifiedFile.getFileName().toString().startsWith(".")) {
continue;
}
String filePath = path + modifiedFile.getFileName();
log.info(event.kind() + filePath);
log.debug("epoll result,path:{}", event.kind() + filePath);
HeraFile hfile = fileMap.get(filePath);

if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ public void testLogFileMonitor() {
monitor.setListener(new DefaultMonitorListener(monitor, readEvent -> {
System.out.println(readEvent.getReadResult().getLines());
}));
String fileName = "/home/work/log/log-manager/.*.log";
String fileName = "/home/work/log/test/provider/server.log.*";
Pattern pattern = Pattern.compile(fileName);
monitor.reg("/home/work/log/log-manager/", it -> true);
monitor.reg("/home/work/log/test/provider/", it -> {
boolean matches = pattern.matcher(it).matches();
log.info("file:{},matches:{}", it, matches);
return matches;
});
log.info("reg finish");
System.in.read();
}
Expand Down

0 comments on commit 1432d97

Please sign in to comment.