Update logging

This commit is contained in:
2022-04-20 23:55:52 +02:00
parent 7140528441
commit 1b62e151a5
7 changed files with 74 additions and 4 deletions

View File

@@ -58,15 +58,16 @@ public class AttributeUpdaterKernel {
}
private void process(File file, ProgressBar progressBar) {
statistic.total();
List<FileAttribute> attributes = processor.loadAttributes(file);
FileInfoDto fileInfo = processor.filterAttributes(attributes);
statistic.total();
if (fileInfo.isChangeNecessary()) {
statistic.shouldChange();
if (!Config.getInstance().isSafeMode()) {
try {
processor.update(file, fileInfo);
statistic.success();
log.info("Updated {}", file.getAbsolutePath());
} catch (IOException e) {
statistic.failedChanging();
log.warn("File couldn't be updated: {}", file.getAbsoluteFile());

View File

@@ -2,6 +2,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LogUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
@@ -60,6 +61,8 @@ public class MkvFileProcessor implements FileProcessor {
LaneType.valueOf(((String) attribute.get("type")).toUpperCase(Locale.ENGLISH))));
}
}
LogUtils.ifDebug(log, fileAttributes);
} catch (IOException e) {
e.printStackTrace();
log.error("File could not be found or loaded!");
@@ -76,6 +79,7 @@ public class MkvFileProcessor implements FileProcessor {
detectCurrentConfiguration(attributes, info, nonForcedTracks);
detectDesiredConfiguration(info, nonForcedTracks);
LogUtils.ifDebug(log, info);
return info;
}
@@ -117,7 +121,7 @@ public class MkvFileProcessor implements FileProcessor {
@Override
public void update(File file, FileInfoDto fileInfo) throws IOException {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append(format("\"%s\" ", Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT)));
sb.append(format("\"%s\" ", file.getAbsolutePath()));
if (fileInfo.isAudioDifferent()) {
@@ -139,6 +143,6 @@ public class MkvFileProcessor implements FileProcessor {
}
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream();
log.debug(IOUtils.toString(new InputStreamReader(inputstream)));
LogUtils.ifDebug(log, IOUtils.toString(new InputStreamReader(inputstream)));
}
}

View File

@@ -21,4 +21,17 @@ public class FileAttribute {
this.forcedTrack = forcedTrack;
this.type = type;
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("[");
sb.append("id=").append(id);
sb.append(", language='").append(language).append('\'');
sb.append(", trackName='").append(trackName).append('\'');
sb.append(", defaultTrack=").append(defaultTrack);
sb.append(", forcedTrack=").append(forcedTrack);
sb.append(", type=").append(type);
sb.append(']');
return sb.toString();
}
}

View File

@@ -39,4 +39,16 @@ public class FileInfoDto {
public boolean areForcedTracksDifferent() {
return desiredForcedSubtitleLanes.size() > 0;
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("[");
sb.append("defaultAudioLane=").append(defaultAudioLane);
sb.append(", defaultSubtitleLane=").append(defaultSubtitleLane);
sb.append(", desiredForcedSubtitleLanes=").append(desiredForcedSubtitleLanes);
sb.append(", desiredAudioLane=").append(desiredAudioLane);
sb.append(", desiredSubtitleLane=").append(desiredSubtitleLane);
sb.append(']');
return sb.toString();
}
}

View File

@@ -0,0 +1,12 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
import org.apache.logging.log4j.Logger;
public class LogUtils {
public static <T> void ifDebug(Logger log, T object) {
if (log.isDebugEnabled()) {
log.debug(object);
}
}
}