corefx - adding logging to file within create home directory to help capture information for debugging issues
This commit is contained in:
parent
113bd3cb6c
commit
7e93b607c4
3 changed files with 39 additions and 27 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.core;
|
||||
|
||||
import com.core.utils.ConfigUtils;
|
||||
import com.jfoenix.controls.JFXDecorator;
|
||||
import com.jfoenix.svg.SVGGlyphLoader;
|
||||
import javafx.application.Application;
|
||||
|
@ -11,14 +12,21 @@ import javafx.scene.image.Image;
|
|||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.Stage;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class Main extends Application {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private static final Path LOG_FILE = Paths.get(System.getProperty("user.home"), ".core", "core.log");
|
||||
|
||||
@Override
|
||||
public void start(Stage window) throws Exception {
|
||||
// set core dir property for logging
|
||||
System.setProperty("core_log", LOG_FILE.toString());
|
||||
|
||||
// check for and create gui home directory
|
||||
ConfigUtils.checkForHomeDirectory();
|
||||
|
||||
// load svg icons
|
||||
SVGGlyphLoader.loadGlyphsFont(getClass().getResourceAsStream("/icons/icomoon_material.svg"),
|
||||
"icomoon.svg");
|
||||
|
@ -51,11 +59,9 @@ public class Main extends Application {
|
|||
|
||||
// configure window
|
||||
window.setOnCloseRequest(event -> {
|
||||
logger.info("exiting gui");
|
||||
Platform.exit();
|
||||
System.exit(0);
|
||||
});
|
||||
window.setOnShown(windowEvent -> logger.info("stage show event"));
|
||||
window.show();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ import java.util.*;
|
|||
|
||||
public final class ConfigUtils {
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private static final Path HOME = Paths.get(System.getProperty("user.home"), ".core");
|
||||
private static final String CONFIG_FILE_NAME = "config.json";
|
||||
private static final String DEFAULT_CONFIG = "/" + CONFIG_FILE_NAME;
|
||||
private static final Path HOME = Paths.get(System.getProperty("user.home"), ".core");
|
||||
private static final Path CONFIG_FILE = Paths.get(HOME.toString(), CONFIG_FILE_NAME);
|
||||
private static final Path XML_DIR = Paths.get(HOME.toString(), "xml");
|
||||
private static final Path MOBILITY_DIR = Paths.get(HOME.toString(), "mobility");
|
||||
|
@ -59,29 +59,31 @@ public final class ConfigUtils {
|
|||
return new NodeTypeConfig(model, display, iconPath.toUri().toString(), services);
|
||||
}
|
||||
|
||||
public static void checkForHomeDirectory() throws IOException {
|
||||
if (!HOME.toFile().exists()) {
|
||||
logger.info("creating core home directory");
|
||||
Files.createDirectory(HOME);
|
||||
Files.createDirectory(XML_DIR);
|
||||
Files.createDirectory(MOBILITY_DIR);
|
||||
Files.createDirectory(ICON_DIR);
|
||||
createDefaultConfigFile();
|
||||
}
|
||||
}
|
||||
|
||||
private static void createDefaultConfigFile() throws IOException {
|
||||
logger.info("creating default configuration");
|
||||
Files.copy(ConfigUtils.class.getResourceAsStream(DEFAULT_CONFIG), CONFIG_FILE);
|
||||
Configuration configuration = readConfig();
|
||||
configuration.setXmlPath(XML_DIR.toString());
|
||||
configuration.setMobilityPath(MOBILITY_DIR.toString());
|
||||
configuration.setIconPath(ICON_DIR.toString());
|
||||
configuration.setNodeTypeConfigs(createDefaults());
|
||||
save(configuration);
|
||||
}
|
||||
|
||||
public static Configuration load() {
|
||||
try {
|
||||
if (!HOME.toFile().exists()) {
|
||||
logger.info("creating core home directory");
|
||||
Files.createDirectory(HOME);
|
||||
Files.createDirectory(XML_DIR);
|
||||
Files.createDirectory(MOBILITY_DIR);
|
||||
Files.createDirectory(ICON_DIR);
|
||||
}
|
||||
|
||||
Configuration configuration;
|
||||
if (!CONFIG_FILE.toFile().exists()) {
|
||||
logger.info("creating default configuration");
|
||||
Files.copy(ConfigUtils.class.getResourceAsStream(DEFAULT_CONFIG), CONFIG_FILE);
|
||||
configuration = readConfig();
|
||||
configuration.setXmlPath(XML_DIR.toString());
|
||||
configuration.setMobilityPath(MOBILITY_DIR.toString());
|
||||
configuration.setIconPath(ICON_DIR.toString());
|
||||
configuration.setNodeTypeConfigs(createDefaults());
|
||||
save(configuration);
|
||||
} else {
|
||||
configuration = readConfig();
|
||||
}
|
||||
Configuration configuration = readConfig();
|
||||
|
||||
// initialize node types
|
||||
for (NodeTypeConfig nodeTypeConfig : configuration.getNodeTypeConfigs()) {
|
||||
|
|
|
@ -4,10 +4,14 @@
|
|||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
<File name="File" fileName="${sys:core_log}">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console"/>
|
||||
<AppenderRef ref="File"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
|
|
Loading…
Add table
Reference in a new issue