replace syso with logger

* replacing all debug/info syso and all syse with log4j 2 logger
This commit is contained in:
Jannik 2017-08-27 20:44:08 +02:00
parent dec767f553
commit 71cf0316ec
23 changed files with 60 additions and 26 deletions

View File

@ -23,5 +23,7 @@
<classpathentry kind="lib" path="src/libraries/jfoenix-1.7.0.jar"/>
<classpathentry kind="lib" path="src/libraries/sqlite-jdbc-3.19.3.jar"/>
<classpathentry kind="lib" path="src/libraries/zip4j-1.3.2.jar"/>
<classpathentry kind="lib" path="src/libraries/log4j-api-2.8.2.jar"/>
<classpathentry kind="lib" path="src/libraries/log4j-core-2.8.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

4
bin/.gitignore vendored
View File

@ -1,3 +1,3 @@
/application/
/datatypes/
/libraries/
/resources/
/log4j2.xml

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,6 +21,8 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.DirectoryChooser;
@ -48,7 +50,7 @@ public class Main extends Application {
@SuppressWarnings("unused")
private File localDB;
private File pictureCache;
private static final Logger LOGGER = LogManager.getLogger(Main.class.getName());
@Override
public void start(Stage primaryStage) {
@ -88,7 +90,8 @@ public class Main extends Application {
//startup checks
//check if client_secret.jason is present
if (Main.class.getResourceAsStream("/resources/client_secret.json") == null) {
System.err.println("client_secret is missing!!!!!");
LOGGER.error("client_secret is missing!!!!!");
// System.err.println("client_secret is missing!!!!!");
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("cemu_UI");
@ -97,22 +100,26 @@ public class Main extends Application {
alert.showAndWait();
}
System.out.println("Directory: " + directory.exists());
System.out.println("configfile: " + configFile.exists());
if(directory.exists() != true){
System.out.println("mkdir all");
LOGGER.info("Directory: " + directory.exists());
LOGGER.info("Configfile: " + configFile.exists());
// System.out.println("Directory: " + directory.exists());
// System.out.println("configfile: " + configFile.exists());
if(!directory.exists()){
LOGGER.info("creating cemu_UI directory");
// System.out.println("mkdir all");
directory.mkdir();
pictureCache.mkdir();
}
if(configFile.exists() != true){
System.out.println("firststart");
if(!configFile.exists()){
LOGGER.info("firststart, setting default values");
// System.out.println("firststart");
firstStart();
mainWindowController.setColor("00a8cc");
mainWindowController.setxPosHelper(0);
mainWindowController.saveSettings();
Runtime.getRuntime().exec("java -jar cemu_UI.jar"); //start again (preventing Bugs)
System.exit(0); //finishes itself
System.exit(0); //finishes itselfdownloading games.db...
}
if(pictureCache.exists() != true){
@ -121,13 +128,15 @@ public class Main extends Application {
if(gamesDBFile.exists() != true){
try {
System.out.print("downloading games.db... ");
LOGGER.info("downloading games.db... ");
// System.out.print("downloading games.db... ");
URL website = new URL(gamesDBdownloadURL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(gamesDBFile);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
System.out.println("done!");
LOGGER.info("finished downloading games.db");
// System.out.println("done!");
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -40,6 +40,8 @@ import javax.swing.ProgressMonitor;
import javax.swing.ProgressMonitorInputStream;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXColorPicker;
@ -211,19 +213,19 @@ public class MainWindowController {
private String cemuPath;
private String romPath;
private String gameExecutePath;
private String selectedGameTitleID;
private String selectedGameTitle;
private String color;
private String dialogBtnStyle;
private String selectedGameTitleID;
private String selectedGameTitle;
private String id;
private String version = "0.1.6";
private String buildNumber = "035";
private String buildNumber = "037";
private String versionName = "Throwback Galaxy";
private int xPos = -200;
private int yPos = 17;
private int xPosHelper;
private int selectedUIDataIndex;
private int selected;
private String id;
private DirectoryChooser directoryChooser = new DirectoryChooser();
private File dirWin = new File(System.getProperty("user.home") + "/Documents/cemu_UI");
private File dirLinux = new File(System.getProperty("user.home") + "/cemu_UI");
@ -238,6 +240,7 @@ public class MainWindowController {
ArrayList<Text> nameText = new ArrayList<Text>();
Properties props = new Properties();
Properties gameProps = new Properties();
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
private MenuItem edit = new MenuItem("edit");
private MenuItem remove = new MenuItem("remove");
private MenuItem update = new MenuItem("update");
@ -297,7 +300,8 @@ public class MainWindowController {
* initialize all actions not initialized by a own method
*/
void initActions() {
System.out.println("initializing Actions... ");
LOGGER.info("initializing Actions... ");
// System.out.println("initializing Actions... ");
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{
@ -568,8 +572,8 @@ public class MainWindowController {
}
}
});
System.out.println("initializing Actions done!");
LOGGER.info("initializing Actions done!");
// System.out.println("initializing Actions done!");
}
@FXML
@ -1264,7 +1268,8 @@ public class MainWindowController {
}
void saveSettings(){
System.out.print("saving Settings... ");
LOGGER.info("saving Settings...");
// System.out.print("saving Settings... ");
OutputStream outputStream; //new output-stream
try {
props.setProperty("cemuPath", getCemuPath());
@ -1285,14 +1290,17 @@ public class MainWindowController {
}
props.storeToXML(outputStream, "cemu_UI settings"); //write new .xml
outputStream.close();
System.out.println("done!");
LOGGER.info("saving Settings done!");
// System.out.println("done!");
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("an error occured", e);
// e.printStackTrace();
}
}
void loadSettings(){
System.out.print("loading settings... ");
LOGGER.info("loading settings...");
// System.out.print("loading settings... ");
InputStream inputStream;
try {
if(System.getProperty("os.name").equals("Linux")){
@ -1309,9 +1317,11 @@ public class MainWindowController {
setCloudService(props.getProperty("cloudService"));
main.cloudController.setFolderID(props.getProperty("folderID"), getCloudService());
inputStream.close();
System.out.println("done!");
LOGGER.info("loading settings done!");
// System.out.println("done!");
} catch (IOException e) {
e.printStackTrace();
LOGGER.error("an error occured", e);
// e.printStackTrace();
}
}

Binary file not shown.

Binary file not shown.

13
src/log4j2.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>