Java Doc, Logging and Cleanup in Log Configuration.
This commit is contained in:
parent
3c3c6c8510
commit
6de4978145
|
@ -11,9 +11,11 @@ import java.io.IOException;
|
||||||
public class App {
|
public class App {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
new LogConfiguration(System.getProperty("user.dir") + System.getProperty("file.separator") + "tournierverwaltung_angrynerds",
|
new LogConfiguration(System.getProperty("user.dir") + System.getProperty("file.separator") +
|
||||||
"ch" + System.getProperty("file.separator") + "zhaw" + System.getProperty("file.separator") + "projekt2" + System.getProperty("file.separator") +
|
"tournierverwaltung_angrynerds", "ch" + System.getProperty("file.separator") + "zhaw" +
|
||||||
"turnierverwaltung" + System.getProperty("file.separator") + "logging" + System.getProperty("file.separator") + "log.properties");
|
System.getProperty("file.separator") + "projekt2" + System.getProperty("file.separator") +
|
||||||
|
"turnierverwaltung" + System.getProperty("file.separator") + "logging" +
|
||||||
|
System.getProperty("file.separator") + "log.properties");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,30 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
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 {
|
public class LogConfiguration {
|
||||||
private static final Logger logger = Logger.getLogger(LogConfiguration.class.getCanonicalName());
|
private static final Logger logger = Logger.getLogger(LogConfiguration.class.getCanonicalName());
|
||||||
private final File mainDir;
|
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");
|
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);
|
this.mainDir = new File(saveLocation);
|
||||||
if (!mainDir.exists()) {
|
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();
|
mainDir.mkdir();
|
||||||
} else {
|
} else {
|
||||||
logger.finer("main directory for log folder already exists");
|
logger.finer("main directory for log folder already exists");
|
||||||
|
@ -25,17 +37,14 @@ public class LogConfiguration {
|
||||||
saves.mkdir();
|
saves.mkdir();
|
||||||
logger.fine("Creating log save directory");
|
logger.fine("Creating log save directory");
|
||||||
} else {
|
} 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") +
|
logger.fine("Getting and reading log config file from: " + propertiesPath);
|
||||||
"turnierverwaltung" + System.getProperty("file.separator") + "logging" + System.getProperty("file.separator") + "log.properties";
|
|
||||||
|
|
||||||
logger.fine("Getting and reading logconfig file from " + propertiesPath);
|
|
||||||
InputStream logConfig = this.getClass().getClassLoader().getResourceAsStream(propertiesPath);
|
InputStream logConfig = this.getClass().getClassLoader().getResourceAsStream(propertiesPath);
|
||||||
LogManager.getLogManager().readConfiguration(logConfig);
|
LogManager.getLogManager().readConfiguration(logConfig);
|
||||||
|
|
||||||
|
|
||||||
Logger.getLogger(LogConfiguration.class.getPackageName());
|
Logger.getLogger(LogConfiguration.class.getPackageName());
|
||||||
|
logger.fine("Finished setting up Logging functionality");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue