diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/common/process/ContinuousProcess.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/common/process/ContinuousProcess.java index f61ce80a..e7a371d4 100644 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/common/process/ContinuousProcess.java +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/common/process/ContinuousProcess.java @@ -64,6 +64,15 @@ public String readErrorLine(){ } } + public String readErrorLines(){ + StringBuilder sb = new StringBuilder(); + String line; + while((line = readErrorLine()) != null){ + sb.append(line).append("\n"); + } + return sb.toString(); + } + public boolean isAlive(){ return this.process.isAlive(); } diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/arp/ArpLogWriter.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/arp/ArpLogWriter.java index 0af0b891..bb381f79 100644 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/arp/ArpLogWriter.java +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/arp/ArpLogWriter.java @@ -14,6 +14,7 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +//TODO: 에러 로그 어떻게 관리할지 생각. 일단 TransientProcess라서 구현 안함 @Slf4j @Component public class ArpLogWriter { diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/mdns/MdnsLogWriter.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/mdns/MdnsLogWriter.java index 0def7ecc..d7d4296f 100644 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/mdns/MdnsLogWriter.java +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/managed/mdns/MdnsLogWriter.java @@ -7,16 +7,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +//TODO: tshark가 종료되지 않더라도 오류가 발생할 수 있으려나? 이 경우에도 로깅이 필요하긴 함 @Slf4j @Component public class MdnsLogWriter { private final Map processes; + private final Map wasDead; private final MdnsLogParser parser; private final ManagedLogDAO dao; private final String sudoPassword; @@ -25,11 +26,13 @@ public MdnsLogWriter(ManagedLogDAO dao, MdnsLogParser parser, NetworkConfig conf this.dao = dao; this.parser = parser; this.sudoPassword = sudoPassword; - this.processes = config.getMdnsList().parallelStream() - .collect(Collectors.toMap( - managedInfo -> managedInfo, - managedInfo -> new MdnsLogProcess(managedInfo, sudoPassword) - )); + this.processes = new HashMap<>(); + this.wasDead = new HashMap<>(); + config.getMdnsList().parallelStream() + .forEach(managedInfo -> { + this.processes.put(managedInfo, new MdnsLogProcess(managedInfo, sudoPassword)); + this.wasDead.put(managedInfo, false); + }); } @Scheduled(initialDelay = 10000, fixedDelay = 10000) @@ -39,7 +42,10 @@ private void writeLogs() { ManagedInfo managedInfo = entry.getKey(); MdnsLogProcess process = entry.getValue(); boolean alive = process.isAlive(); - if (!alive) log.error("[managed - mdns({})] dead", managedInfo.ssid()); + if (!alive && wasDead.get(managedInfo).equals(Boolean.FALSE)) { + wasDead.put(managedInfo, true); + log.error("[managed - mdns({})] dead :\n{}", managedInfo.ssid(), process.readErrorLines()); + } return alive;}) .flatMap(entry -> { ManagedInfo managedInfo = entry.getKey(); diff --git a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/monitor/MonitorLogWriter.java b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/monitor/MonitorLogWriter.java index 8b3096a3..365c77c3 100644 --- a/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/monitor/MonitorLogWriter.java +++ b/modules/infrastructure/log-writer/src/main/java/com/whoz_in/log_writer/monitor/MonitorLogWriter.java @@ -12,6 +12,7 @@ @Component public class MonitorLogWriter { private MonitorLogProcess process; //교체될 수 있으므로 final X + private Boolean wasDead = false; private final MonitorLogParser parser; private final MonitorLogDAO repo; private final String sudoPassword; @@ -27,7 +28,10 @@ public MonitorLogWriter(MonitorLogParser parser, MonitorLogDAO repo, NetworkConf @Scheduled(initialDelay = 10000, fixedDelay = 10000) private void saveLogs(){ if (!process.isAlive()) { - log.error("[monitor] dead"); + if (wasDead.equals(Boolean.FALSE)) { + log.error("[monitor] dead:\n{}", process.readErrorLines()); + wasDead = true; + } return; } Set macs = new HashSet<>();