log4j entfernt, ini4j hinzugefügt, cfg4j funktioniert
This commit is contained in:
16
src/log4j.properties
Normal file
16
src/log4j.properties
Normal 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
|
@ -1,22 +1,19 @@
|
||||
package tourplaner;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import tourplaner.business.LogHelper;
|
||||
|
||||
import tourplaner.business.TourPlaner;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception{
|
||||
TourPlaner tourplaner = new TourPlaner(primaryStage);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,38 @@
|
||||
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 {
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +1,34 @@
|
||||
package tourplaner.business;
|
||||
import org.apache.log4j.*;
|
||||
import org.apache.log4j.xml.DOMConfigurator;
|
||||
|
||||
|
||||
/**
|
||||
* Hilft beim Logging mit log4j
|
||||
*/
|
||||
public class LogHelper{
|
||||
private static Logger logger = Logger.getRootLogger();
|
||||
|
||||
/**
|
||||
* Holt den passenden logger für die Anwendung
|
||||
* @return Der Aktuelle passende Logger, null bei error
|
||||
* Logging in file und Console
|
||||
* @param msg Nachricht in dem Log
|
||||
* @param name Name des Log Eintrags
|
||||
*/
|
||||
public static Logger getLogger() {
|
||||
try {
|
||||
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 info(String msg, String name){
|
||||
getLog(name).info(msg);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,8 +17,13 @@ public class TourPlaner{
|
||||
* @param primaryStage Stage für den Presenter
|
||||
*/
|
||||
public TourPlaner(Stage primaryStage){
|
||||
logger = LogHelper.getLogger(); // Initialiesiert das Logging
|
||||
logger.info("Tour planer Startet!");
|
||||
PresenterMain presenterMain = new PresenterMain(primaryStage, logger); // Start Presenter/GUI
|
||||
try {
|
||||
String startText = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "start", "message");
|
||||
LogHelper.info(startText, "TourPlaner");
|
||||
PresenterMain presenterMain = new PresenterMain(primaryStage); // Start Presenter/GUI
|
||||
} catch (IOException e) {
|
||||
LogHelper.fatal(e.getMessage(), "TourPlanerConfig");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import org.apache.log4j.Logger;
|
||||
import tourplaner.business.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -16,9 +17,9 @@ public class PresenterMain {
|
||||
/**
|
||||
* Startet die Gui
|
||||
* @param primaryStage Stage der GUI
|
||||
* @param logger Aktueller Logger
|
||||
*
|
||||
*/
|
||||
public PresenterMain(Stage primaryStage, Logger logger){
|
||||
public PresenterMain(Stage primaryStage){
|
||||
Parent root = null;
|
||||
try {
|
||||
root = FXMLLoader.load(getClass().getResource("../ui/tourplaner.fxml"));
|
||||
@ -26,7 +27,7 @@ public class PresenterMain {
|
||||
primaryStage.setScene(new Scene(root, 600, 600));
|
||||
primaryStage.show();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage());
|
||||
LogHelper.error(e.getMessage(), "PresenterMain");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,7 +52,7 @@
|
||||
<?import javafx.scene.paint.Color?>
|
||||
<?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>
|
||||
<MenuBar VBox.vgrow="NEVER">
|
||||
<menus>
|
||||
|
Reference in New Issue
Block a user