log4j entfernt, ini4j hinzugefügt, cfg4j funktioniert

This commit is contained in:
Georg Reisinger 2021-02-26 16:10:10 +01:00
parent 2e8dd202d9
commit 0c8ccce950
19 changed files with 2786 additions and 43 deletions

2660
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4"> <module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset" name="ConfigHelper" removed="false">
<file>file://$MODULE_DIR$/src/tourplaner/business/ConfigHelper.java</file>
</fileset>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
@ -8,10 +17,8 @@
<orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" /> <orderEntry type="jdk" jdkName="11" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" /> <orderEntry type="library" name="lib" level="project" />
<orderEntry type="library" name="log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="junit:junit:4.13.2" level="project" /> <orderEntry type="library" name="junit:junit:4.13.2" level="project" />
<orderEntry type="library" name="org.cfg4j:cfg4j-core:4.4.1" level="project" /> <orderEntry type="library" name="org.slf4j:slf4j-log4j12:1.7.12" level="project" />
<orderEntry type="library" name="org.cfg4j:cfg4j:3.3.2" level="project" /> <orderEntry type="library" name="org.ini4j:ini4j:0.5.4" level="project" />
<orderEntry type="library" name="org.springframework:spring-beans:4.0.0.RELEASE" level="project" />
</component> </component>
</module> </module>

2
conf.ini Normal file
View File

@ -0,0 +1,2 @@
[start]
message = Tour Planer App gestartet

6
log/log4j/log.out Normal file
View File

@ -0,0 +1,6 @@
Tour planer Startet!
Tour planer Startet!
App started
2021-02-26 15:59:44 INFO TourPlaner:15 - App started
2021-02-26 16:06:01 FATAL TourPlanerConfig:27 - C:\Users\georg\OneDrive\FH\Swe\Tourplaner\conf.ini (Das System kann die angegebene Datei nicht finden)
2021-02-26 16:08:31 INFO TourPlaner:15 - Tour Planer App gestartet

0
logs/tourplaner.log Normal file
View File

View File

@ -0,0 +1,16 @@
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log/log4j/log.out
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

View File

@ -52,7 +52,7 @@
<?import javafx.scene.paint.Color?> <?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<VBox prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1"> <VBox prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<MenuBar VBox.vgrow="NEVER"> <MenuBar VBox.vgrow="NEVER">
<menus> <menus>

16
src/log4j.properties Normal file
View File

@ -0,0 +1,16 @@
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log/log4j/log.out
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

View File

@ -1,22 +1,19 @@
package tourplaner; package tourplaner;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import tourplaner.business.LogHelper;
import tourplaner.business.TourPlaner; import tourplaner.business.TourPlaner;
public class Main extends Application { public class Main extends Application {
public static void main(String[] args) throws Exception {
launch(args);
}
@Override @Override
public void start(Stage primaryStage) throws Exception{ public void start(Stage primaryStage) throws Exception{
TourPlaner tourplaner = new TourPlaner(primaryStage); TourPlaner tourplaner = new TourPlaner(primaryStage);
} }
public static void main(String[] args) {
launch(args);
}
} }

View File

@ -1,8 +1,38 @@
package tourplaner.business; package tourplaner.business;
import org.springframework.beans.factory.annotation.Value; import org.ini4j.Wini;
import java.io.File;
import java.io.IOException;
public class ConfigHelper { public class ConfigHelper {
@Value("${configFilesPath:./config}")
private String filesPath; // Run with -DconfigFilesPath=<configFilesPath> parameter to override public static String standartConfig = "conf.ini";
public static int getIniInt(String filename, String sectionName, String optionName) throws IOException {
Wini ini = new Wini(new File(filename));
return ini.get(sectionName, optionName, int.class);
}
public static String getIniString(String filename, String sectionName, String optionName) throws IOException {
Wini ini = new Wini(new File(filename));
return ini.get(sectionName, optionName, String.class);
}
public static void setIniString(String filename, String sectionName, String optionName, String value) throws IOException {
Wini ini = new Wini(new File(filename));
ini.put(sectionName, optionName, value);
ini.store();
}
public static void setIniInt(String filename, String sectionName, String optionName, int value) throws IOException {
Wini ini = new Wini(new File(filename));
ini.put(sectionName, optionName, value);
ini.store();
}
public static String getStandartConfig() {
return standartConfig;
}
} }

View File

@ -1,31 +1,34 @@
package tourplaner.business; package tourplaner.business;
import org.apache.log4j.*; import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;
/** /**
* Hilft beim Logging mit log4j * Hilft beim Logging mit log4j
*/ */
public class LogHelper{ public class LogHelper{
private static Logger logger = Logger.getRootLogger();
/** /**
* Holt den passenden logger für die Anwendung * Logging in file und Console
* @return Der Aktuelle passende Logger, null bei error * @param msg Nachricht in dem Log
* @param name Name des Log Eintrags
*/ */
public static Logger getLogger() { public static void info(String msg, String name){
try { getLog(name).info(msg);
SimpleLayout layout = new SimpleLayout();
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
logger.addAppender(consoleAppender);
FileAppender fileAppender = new FileAppender(layout, "../../../logs/tourplaner.log", true);
logger.addAppender(fileAppender);
// ALL | DEBUG | INFO | WARN | ERROR | FATAL | OFF:
logger.setLevel(Level.DEBUG);
return logger;
} catch (Exception ex) {
System.err.println(ex.getMessage());
return null;
}
} }
public static void warn(String msg, String name){
getLog(name).warn(msg);
}
public static void error(String msg, String name){
getLog(name).error(msg);
}
public static void fatal(String msg, String name){
getLog(name).fatal(msg);
}
private static Logger getLog(String name){
return Logger.getLogger(name); // Initialiesiert das Logging
}
} }

View File

@ -17,8 +17,13 @@ public class TourPlaner{
* @param primaryStage Stage für den Presenter * @param primaryStage Stage für den Presenter
*/ */
public TourPlaner(Stage primaryStage){ public TourPlaner(Stage primaryStage){
logger = LogHelper.getLogger(); // Initialiesiert das Logging try {
logger.info("Tour planer Startet!"); String startText = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "message");
PresenterMain presenterMain = new PresenterMain(primaryStage, logger); // Start Presenter/GUI LogHelper.info(startText, "TourPlaner");
PresenterMain presenterMain = new PresenterMain(primaryStage); // Start Presenter/GUI
} catch (IOException e) {
LogHelper.fatal(e.getMessage(), "TourPlanerConfig");
}
} }
} }

View File

@ -5,6 +5,7 @@ import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import tourplaner.business.LogHelper;
import java.io.IOException; import java.io.IOException;
@ -16,9 +17,9 @@ public class PresenterMain {
/** /**
* Startet die Gui * Startet die Gui
* @param primaryStage Stage der GUI * @param primaryStage Stage der GUI
* @param logger Aktueller Logger *
*/ */
public PresenterMain(Stage primaryStage, Logger logger){ public PresenterMain(Stage primaryStage){
Parent root = null; Parent root = null;
try { try {
root = FXMLLoader.load(getClass().getResource("../ui/tourplaner.fxml")); root = FXMLLoader.load(getClass().getResource("../ui/tourplaner.fxml"));
@ -26,7 +27,7 @@ public class PresenterMain {
primaryStage.setScene(new Scene(root, 600, 600)); primaryStage.setScene(new Scene(root, 600, 600));
primaryStage.show(); primaryStage.show();
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage()); LogHelper.error(e.getMessage(), "PresenterMain");
} }
} }

View File

@ -52,7 +52,7 @@
<?import javafx.scene.paint.Color?> <?import javafx.scene.paint.Color?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<VBox prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1"> <VBox prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/11.0.2" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<MenuBar VBox.vgrow="NEVER"> <MenuBar VBox.vgrow="NEVER">
<menus> <menus>