From 6de4978145346651899d8fcc86da1209a2a0c1c5 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Fri, 13 May 2022 18:21:52 +0200 Subject: [PATCH] Java Doc, Logging and Cleanup in Log Configuration. --- .../zhaw/projekt2/turnierverwaltung/App.java | 8 +++-- .../turnierverwaltung/LogConfiguration.java | 29 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java index 15a07cc..f82911c 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/App.java @@ -11,9 +11,11 @@ import java.io.IOException; public class App { public static void main(String[] args) { try { - new LogConfiguration(System.getProperty("user.dir") + System.getProperty("file.separator") + "tournierverwaltung_angrynerds", - "ch" + System.getProperty("file.separator") + "zhaw" + System.getProperty("file.separator") + "projekt2" + System.getProperty("file.separator") + - "turnierverwaltung" + System.getProperty("file.separator") + "logging" + System.getProperty("file.separator") + "log.properties"); + new LogConfiguration(System.getProperty("user.dir") + System.getProperty("file.separator") + + "tournierverwaltung_angrynerds", "ch" + System.getProperty("file.separator") + "zhaw" + + System.getProperty("file.separator") + "projekt2" + System.getProperty("file.separator") + + "turnierverwaltung" + System.getProperty("file.separator") + "logging" + + System.getProperty("file.separator") + "log.properties"); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LogConfiguration.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LogConfiguration.java index b15c578..9fd1b52 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LogConfiguration.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/LogConfiguration.java @@ -3,18 +3,30 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.logging.*; - +import java.util.logging.LogManager; +import java.util.logging.Logger; +/** + * Class in charge of setting up the Logging functionality properly + * For further Log settings look into the properties.log file + */ public class LogConfiguration { private static final Logger logger = Logger.getLogger(LogConfiguration.class.getCanonicalName()); private final File mainDir; - public LogConfiguration(String saveLocation, String logFileLocation) throws IOException { + /** + * Constructor of LogConfiguration, does the whole setup including reading the properties and setting up a + * directory for the log files also starts the root logger. + * + * @param saveLocation where the log files should be placed in + * @param propertiesPath location of the properties.log file + * @throws IOException if error occurs while reading the log file + */ + public LogConfiguration(String saveLocation, String propertiesPath) throws IOException { logger.fine("Starts setting up a main directory in which a folder with the log files will be placed, if not already exists"); this.mainDir = new File(saveLocation); if (!mainDir.exists()) { - logger.fine("Creating main directory for log ordner in given path" + saveLocation); + logger.fine("Creating main directory for log folder in given path" + saveLocation); mainDir.mkdir(); } else { logger.finer("main directory for log folder already exists"); @@ -25,17 +37,14 @@ public class LogConfiguration { saves.mkdir(); logger.fine("Creating log save directory"); } else { - logger.finer("log save directory already exists"); + logger.finer("Log save directory already exists"); } - String propertiesPath = "ch" + System.getProperty("file.separator") + "zhaw" + System.getProperty("file.separator") + "projekt2" + System.getProperty("file.separator") + - "turnierverwaltung" + System.getProperty("file.separator") + "logging" + System.getProperty("file.separator") + "log.properties"; - - logger.fine("Getting and reading logconfig file from " + propertiesPath); + logger.fine("Getting and reading log config file from: " + propertiesPath); InputStream logConfig = this.getClass().getClassLoader().getResourceAsStream(propertiesPath); LogManager.getLogManager().readConfiguration(logConfig); - Logger.getLogger(LogConfiguration.class.getPackageName()); + logger.fine("Finished setting up Logging functionality"); } }