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) { private void process(File file, ProgressBar progressBar) {
statistic.total();
List<FileAttribute> attributes = processor.loadAttributes(file); List<FileAttribute> attributes = processor.loadAttributes(file);
FileInfoDto fileInfo = processor.filterAttributes(attributes); FileInfoDto fileInfo = processor.filterAttributes(attributes);
statistic.total();
if (fileInfo.isChangeNecessary()) { if (fileInfo.isChangeNecessary()) {
statistic.shouldChange(); statistic.shouldChange();
if (!Config.getInstance().isSafeMode()) { if (!Config.getInstance().isSafeMode()) {
try { try {
processor.update(file, fileInfo); processor.update(file, fileInfo);
statistic.success(); statistic.success();
log.info("Updated {}", file.getAbsolutePath());
} catch (IOException e) { } catch (IOException e) {
statistic.failedChanging(); statistic.failedChanging();
log.warn("File couldn't be updated: {}", file.getAbsoluteFile()); 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.config.Config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LogUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -60,6 +61,8 @@ public class MkvFileProcessor implements FileProcessor {
LaneType.valueOf(((String) attribute.get("type")).toUpperCase(Locale.ENGLISH)))); LaneType.valueOf(((String) attribute.get("type")).toUpperCase(Locale.ENGLISH))));
} }
} }
LogUtils.ifDebug(log, fileAttributes);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
log.error("File could not be found or loaded!"); log.error("File could not be found or loaded!");
@@ -76,6 +79,7 @@ public class MkvFileProcessor implements FileProcessor {
detectCurrentConfiguration(attributes, info, nonForcedTracks); detectCurrentConfiguration(attributes, info, nonForcedTracks);
detectDesiredConfiguration(info, nonForcedTracks); detectDesiredConfiguration(info, nonForcedTracks);
LogUtils.ifDebug(log, info);
return info; return info;
} }
@@ -117,7 +121,7 @@ public class MkvFileProcessor implements FileProcessor {
@Override @Override
public void update(File file, FileInfoDto fileInfo) throws IOException { 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\" ", Config.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT)));
sb.append(format("\"%s\" ", file.getAbsolutePath())); sb.append(format("\"%s\" ", file.getAbsolutePath()));
if (fileInfo.isAudioDifferent()) { if (fileInfo.isAudioDifferent()) {
@@ -139,6 +143,6 @@ public class MkvFileProcessor implements FileProcessor {
} }
InputStream inputstream = Runtime.getRuntime().exec(sb.toString()).getInputStream(); 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.forcedTrack = forcedTrack;
this.type = type; 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() { public boolean areForcedTracksDifferent() {
return desiredForcedSubtitleLanes.size() > 0; 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);
}
}
}

View File

@@ -0,0 +1,28 @@
Configuration:
name: DefaultLogger
Appenders:
Console:
name: Console_Out
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
ThresholdFilter:
level: debug
File:
name: FileAppender
fileName: default.log
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
ThresholdFilter:
level: debug
Loggers:
Root:
level: debug
AppenderRef:
- ref: Console_Out
- ref: FileAppender
Logger:
name: "com.zaxxer.hikari.HikariConfig"
level: info
AppenderRef:
- ref: Console_Out
- ref: FileAppender

View File

@@ -10,7 +10,7 @@ Configuration:
level: info level: info
Loggers: Loggers:
Root: Root:
level: debug level: info
AppenderRef: AppenderRef:
- ref: FileAppender - ref: FileAppender
Logger: Logger: