Skip to content

Commit

Permalink
replace syso with logger
Browse files Browse the repository at this point in the history
* replacing all debug/info syso and all syse with log4j 2 logger
  • Loading branch information
Seil0 committed Aug 27, 2017
1 parent dec767f commit 71cf031
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 2 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/application/
/datatypes/
/libraries/
/resources/
/log4j2.xml
Binary file modified bin/application/Main.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$1.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$10.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$11.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$12.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$2.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$3.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$4.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$5.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$6.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$7.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$8.class
Binary file not shown.
Binary file modified bin/application/MainWindowController$9.class
Binary file not shown.
Binary file modified bin/application/MainWindowController.class
Binary file not shown.
Binary file added bin/libraries/log4j-api-2.8.2.jar
Binary file not shown.
Binary file added bin/libraries/log4j-core-2.8.2.jar
Binary file not shown.
31 changes: 20 additions & 11 deletions src/application/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -88,7 +90,8 @@ private void mainWindow(){
//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");
Expand All @@ -97,22 +100,26 @@ private void mainWindow(){
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){
Expand All @@ -121,13 +128,15 @@ private void mainWindow(){

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();
}
Expand Down
36 changes: 23 additions & 13 deletions src/application/MainWindowController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -297,7 +300,8 @@ void initUI(){
* 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)->{
Expand Down Expand Up @@ -568,8 +572,8 @@ public void handle(MouseEvent mouseEvent) {
}
}
});

System.out.println("initializing Actions done!");
LOGGER.info("initializing Actions done!");
// System.out.println("initializing Actions done!");
}

@FXML
Expand Down Expand Up @@ -1264,7 +1268,8 @@ private void applyColor() {
}

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());
Expand All @@ -1285,14 +1290,17 @@ void saveSettings(){
}
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")){
Expand All @@ -1309,9 +1317,11 @@ void loadSettings(){
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();
}
}

Expand Down
Binary file added src/libraries/log4j-api-2.8.2.jar
Binary file not shown.
Binary file added src/libraries/log4j-core-2.8.2.jar
Binary file not shown.
13 changes: 13 additions & 0 deletions src/log4j2.xml
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 71cf031

Please sign in to comment.