Parameterize log4j2 configs

This commit is contained in:
RatzzFatzz
2026-01-15 13:32:35 +01:00
parent cce84f5c15
commit a97ed89d08
7 changed files with 58 additions and 32 deletions

View File

@@ -29,7 +29,7 @@
<resource>
<directory>src/main/resources</directory>
<includes>
<include>log4j2.yaml</include>
<include>log4j2.yml</include>
</includes>
</resource>
</resources>
@@ -64,7 +64,7 @@
<resource>
<directory>src/main/resources</directory>
<includes>
<include>log4j2-windows.yaml</include>
<include>log4j2-windows.yml</include>
</includes>
</resource>
</resources>
@@ -161,7 +161,7 @@
<resource>
<directory>src/main/resources</directory>
<includes>
<include>log4j2-debian.yaml</include>
<include>log4j2-debian.yml</include>
</includes>
</resource>
</resources>

View File

@@ -1 +1 @@
java -Dlog4j2.configurationFile=log4j2-debian.yaml -jar /usr/lib/${project.artifactId}/${project.artifactId}-${project.version}.jar "$@"
java -Dlog4j2.configurationFile=log4j2-debian.yml -jar /usr/lib/${project.artifactId}/${project.artifactId}-${project.version}.jar "$@"

View File

@@ -43,14 +43,7 @@ public class CommandRunner implements Runnable {
System.out.println("Safemode active. No files will be changed!");
}
String userLocal = getLogDirectory();
if (userLocal == null) {
log.error("Could not load log4j2 log info");
System.out.println("Could not load log4j2 log info");
System.exit(1);
}
LastExecutionHandler lastExecutionHandler = config.isOnlyNewFiles() ? new LastExecutionHandler(userLocal) : null;
LastExecutionHandler lastExecutionHandler = config.isOnlyNewFiles() ? new LastExecutionHandler(getApplicationHome()) : null;
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate(), lastExecutionHandler);
FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter));
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
@@ -61,7 +54,7 @@ public class CommandRunner implements Runnable {
kernel.execute();
}
public String getLogDirectory() {
public String getApplicationHome() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
@@ -72,7 +65,9 @@ public class CommandRunner implements Runnable {
}
}
log.warn("No file appender found in configuration");
log.error("Could not load log4j2 path info");
System.out.println("Could not load log4j2 path info");
System.exit(1);
return null;
}
}

View File

@@ -1,12 +1,20 @@
Configuration:
name: DefaultLogger
name: MainConfig
Properties:
Property:
- name: logDir
value: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs
- name: logPattern
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Appenders:
RollingFile:
name: FileAppender
fileName: logs/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
fileName: ${logDir}/application.log
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Pattern: logPattern
ThresholdFilter:
level: debug
Policies:

View File

@@ -1,18 +1,25 @@
Configuration:
name: DefaultLogger
Properties:
Property:
- name: logDir
value: "./logs"
- name: log_pattern
value: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
Appenders:
Console:
name: Console_Out
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
Pattern: ${log_pattern}
ThresholdFilter:
level: debug
RollingFile:
name: FileAppender
fileName: logs/application.log
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
fileName: ${logDir}/application.log
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
Pattern: logPattern
ThresholdFilter:
level: debug
Policies:

View File

@@ -1,12 +1,20 @@
Configuration:
name: DefaultLogger
name: WindowsConfig
Properties:
Property:
- name: logDir
value: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs
- name: logPattern
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Appenders:
RollingFile:
name: FileAppender
fileName: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/application.log
filePattern: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
fileName: ${logDir}/application.log
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Pattern: logPattern
ThresholdFilter:
level: debug
Policies:
@@ -15,7 +23,7 @@ Configuration:
DefaultRolloverStrategy:
max: 30
Delete:
basePath: archive
basePath: logs/archive
maxDepth: 1
IfLastModified:
age: 30d

View File

@@ -1,12 +1,20 @@
Configuration:
name: DefaultLogger
name: MainConfig
Properties:
Property:
- name: logDir
value: ./logs
- name: logPattern
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Appenders:
RollingFile:
name: FileAppender
fileName: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/application.log
filePattern: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
fileName: ${logDir}/application.log
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
PatternLayout:
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
Pattern: logPattern
ThresholdFilter:
level: debug
Policies: