mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-31 13:34:22 +02:00
[insteon] Truncate debug log files when starting monitor (#18295)
Signed-off-by: Jeremy Setton <jeremy.setton@gmail.com>
This commit is contained in:
+14
-6
@@ -271,11 +271,19 @@ public class DebugCommand extends InsteonCommand implements PortListener {
|
|||||||
return getBindingDataFilePath(MSG_EVENTS_FILE_PREFIX + "-" + name + ".log");
|
return getBindingDataFilePath(MSG_EVENTS_FILE_PREFIX + "-" + name + ".log");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearMonitorFiles(@Nullable DeviceAddress address) {
|
private void clearMonitorFiles() {
|
||||||
String prefix = address == null ? MSG_EVENTS_FILE_PREFIX
|
getBindingDataFilePaths(MSG_EVENTS_FILE_PREFIX).map(Path::toFile).forEach(File::delete);
|
||||||
: getMsgEventsFilePath(address).getFileName().toString();
|
}
|
||||||
|
|
||||||
getBindingDataFilePaths(prefix).map(Path::toFile).forEach(File::delete);
|
private void truncateMonitorFile(DeviceAddress address) {
|
||||||
|
try {
|
||||||
|
Path path = getMsgEventsFilePath(address);
|
||||||
|
|
||||||
|
Files.createDirectories(path.getParent());
|
||||||
|
Files.writeString(path, "", StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.warn("failed to truncate message event file", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logMessageEvent(Msg msg) {
|
private void logMessageEvent(Msg msg) {
|
||||||
@@ -315,7 +323,7 @@ public class DebugCommand extends InsteonCommand implements PortListener {
|
|||||||
monitoredAddresses.clear();
|
monitoredAddresses.clear();
|
||||||
console.println("Started monitoring all devices.");
|
console.println("Started monitoring all devices.");
|
||||||
console.println("Message events logged in " + getBindingDataDirPath());
|
console.println("Message events logged in " + getBindingDataDirPath());
|
||||||
clearMonitorFiles(null);
|
clearMonitorFiles();
|
||||||
} else {
|
} else {
|
||||||
DeviceAddress address = InsteonAddress.isValid(arg) ? new InsteonAddress(arg)
|
DeviceAddress address = InsteonAddress.isValid(arg) ? new InsteonAddress(arg)
|
||||||
: X10Address.isValid(arg) ? new X10Address(arg) : null;
|
: X10Address.isValid(arg) ? new X10Address(arg) : null;
|
||||||
@@ -324,7 +332,7 @@ public class DebugCommand extends InsteonCommand implements PortListener {
|
|||||||
} else if (monitoredAddresses.add(address)) {
|
} else if (monitoredAddresses.add(address)) {
|
||||||
console.println("Started monitoring the device " + address + ".");
|
console.println("Started monitoring the device " + address + ".");
|
||||||
console.println("Message events logged in " + getMsgEventsFilePath(address));
|
console.println("Message events logged in " + getMsgEventsFilePath(address));
|
||||||
clearMonitorFiles(address);
|
truncateMonitorFile(address);
|
||||||
} else {
|
} else {
|
||||||
console.println("Already monitoring the device " + address + ".");
|
console.println("Already monitoring the device " + address + ".");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user