|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue