Archived
[ADDED] Erste Implementierung einer Logger Klasse
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package com.ixab.ConfigHandling;
|
package com.ixab.ConfigHandling;
|
||||||
|
|
||||||
|
import com.ixab.Logging.Logger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class ConfigFileIOHandler {
|
public class ConfigFileIOHandler {
|
||||||
@@ -18,7 +20,7 @@ public class ConfigFileIOHandler {
|
|||||||
return null;
|
return null;
|
||||||
}catch(ClassNotFoundException e)
|
}catch(ClassNotFoundException e)
|
||||||
{
|
{
|
||||||
System.out.println("Config class not found");
|
Logger.print("Config class not found");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -33,7 +35,7 @@ public class ConfigFileIOHandler {
|
|||||||
out.writeObject(c);
|
out.writeObject(c);
|
||||||
out.close();
|
out.close();
|
||||||
fileOut.close();
|
fileOut.close();
|
||||||
System.out.println("Config data is saved in config.dat");
|
Logger.print("Config data is saved in config.dat");
|
||||||
}catch(IOException i)
|
}catch(IOException i)
|
||||||
{
|
{
|
||||||
i.printStackTrace();
|
i.printStackTrace();
|
||||||
@@ -45,4 +47,7 @@ public class ConfigFileIOHandler {
|
|||||||
public static void save(Config c) {
|
public static void save(Config c) {
|
||||||
save(c, "config.dat");
|
save(c, "config.dat");
|
||||||
}
|
}
|
||||||
|
public static void save() {
|
||||||
|
save(ConfigFileInstanceHandler.getConfig(), "config.dat");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,9 +48,7 @@ public class AddStreamDialog extends JDialog {
|
|||||||
private void onOK() {
|
private void onOK() {
|
||||||
ConfigFileInstanceHandler.getConfig().addStream(textField1.getText());
|
ConfigFileInstanceHandler.getConfig().addStream(textField1.getText());
|
||||||
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
|
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
|
||||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = true;
|
|
||||||
MainWindowGate.getMainWindow().refreshStreamsComboBox();
|
MainWindowGate.getMainWindow().refreshStreamsComboBox();
|
||||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = false;
|
|
||||||
ErrorMessageGate.setErrorText("Stream \""+textField1.getText()+"\" hinzugefügt.");
|
ErrorMessageGate.setErrorText("Stream \""+textField1.getText()+"\" hinzugefügt.");
|
||||||
textField1.setText("");
|
textField1.setText("");
|
||||||
dispose();
|
dispose();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.ixab.ConfigHandling.ConfigFileIOHandler;
|
|||||||
import com.ixab.ConfigHandling.ConfigFileInstanceHandler;
|
import com.ixab.ConfigHandling.ConfigFileInstanceHandler;
|
||||||
import com.ixab.ConfigHandling.StreamConfigItem;
|
import com.ixab.ConfigHandling.StreamConfigItem;
|
||||||
import com.ixab.ConfigHandling.StreamConfigSorter;
|
import com.ixab.ConfigHandling.StreamConfigSorter;
|
||||||
|
import com.ixab.Logging.Logger;
|
||||||
import com.ixab.StreamHandling.StreamOpener;
|
import com.ixab.StreamHandling.StreamOpener;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -31,7 +32,7 @@ public class MainWindow {
|
|||||||
|
|
||||||
private JLabel errorLabel;
|
private JLabel errorLabel;
|
||||||
private JButton buttonReloadStreamData;
|
private JButton buttonReloadStreamData;
|
||||||
protected boolean lockStreamInfoGetter = false;
|
private boolean lockStreamInfoGetter = false;
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
|
|
||||||
@@ -93,6 +94,12 @@ public class MainWindow {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
private void startUpdaterThread() {
|
private void startUpdaterThread() {
|
||||||
|
if (updateThread != null) {
|
||||||
|
if (updateThread.isAlive()) {
|
||||||
|
updateThread.interrupt();
|
||||||
|
Logger.print("Thread interrupted", this);
|
||||||
|
}
|
||||||
|
}
|
||||||
Runnable r = new Runnable() {
|
Runnable r = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -117,7 +124,7 @@ public class MainWindow {
|
|||||||
}
|
}
|
||||||
private void makeAPause(long time) {
|
private void makeAPause(long time) {
|
||||||
try {
|
try {
|
||||||
System.out.println("schläft "+time/1000.0+" sek");
|
Logger.print("schläft "+time/1000.0+" sek", this);
|
||||||
Thread.sleep(time);
|
Thread.sleep(time);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -125,12 +132,14 @@ public class MainWindow {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Thread t = new Thread(r);
|
Thread t = new Thread(r);
|
||||||
|
this.updateThread = t;
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
private void updateStreamDetails() {
|
private void updateStreamDetails() {
|
||||||
if (updateThread != null) {
|
if (updateThread != null) {
|
||||||
if (updateThread.isAlive()) {
|
if (updateThread.isAlive()) {
|
||||||
updateThread.interrupt();
|
updateThread.interrupt();
|
||||||
|
Logger.print("Thread interrupted" , this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Runnable r = new Runnable() {
|
Runnable r = new Runnable() {
|
||||||
|
|||||||
@@ -74,9 +74,7 @@ public class SettingsWindow extends JDialog {
|
|||||||
ConfigFileInstanceHandler.getConfig().addStream(name);
|
ConfigFileInstanceHandler.getConfig().addStream(name);
|
||||||
}
|
}
|
||||||
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
|
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
|
||||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = true;
|
|
||||||
MainWindowGate.getMainWindow().refreshStreamsComboBox();
|
MainWindowGate.getMainWindow().refreshStreamsComboBox();
|
||||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = false;
|
|
||||||
}
|
}
|
||||||
buttonImportUserData.setText(old);
|
buttonImportUserData.setText(old);
|
||||||
ErrorMessageGate.setErrorText("Streams von "+twitchBenutzernameTextField.getText()+" hinzugefügt.");
|
ErrorMessageGate.setErrorText("Streams von "+twitchBenutzernameTextField.getText()+" hinzugefügt.");
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package com.ixab.Logging;
|
||||||
|
|
||||||
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
private static String bracketOpen = "[";
|
||||||
|
private static String bracketClosed = "]";
|
||||||
|
private static String spacer = " ";
|
||||||
|
public static void print(String s, Class c) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
sb.append(bracketOpen);
|
||||||
|
sb.append(c.getCanonicalName());
|
||||||
|
sb.append(bracketClosed);
|
||||||
|
sb.append(spacer);
|
||||||
|
sb.append(bracketOpen);
|
||||||
|
sb.append(time);
|
||||||
|
sb.append(bracketClosed);
|
||||||
|
sb.append(spacer);
|
||||||
|
sb.append(s);
|
||||||
|
System.out.println(sb.toString());
|
||||||
|
}
|
||||||
|
public static void print(String s) {
|
||||||
|
print(s, Logger.class);
|
||||||
|
}
|
||||||
|
public static void print(String s, Object o) {
|
||||||
|
print(s, o.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.ixab.StreamHandling;
|
|||||||
|
|
||||||
import com.ixab.ConfigHandling.Config;
|
import com.ixab.ConfigHandling.Config;
|
||||||
import com.ixab.GUI.MainWindow;
|
import com.ixab.GUI.MainWindow;
|
||||||
|
import com.ixab.Logging.Logger;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -25,15 +26,15 @@ public class StreamOpener extends Thread {
|
|||||||
String line=null;
|
String line=null;
|
||||||
|
|
||||||
while((line=input.readLine()) != null) {
|
while((line=input.readLine()) != null) {
|
||||||
System.out.println(line);
|
Logger.print(line, this);
|
||||||
// TODO: analyze livestreamer output and inform gui on errors
|
// TODO: analyze livestreamer output and inform gui on errors
|
||||||
}
|
}
|
||||||
|
|
||||||
int exitVal = pr.waitFor();
|
int exitVal = pr.waitFor();
|
||||||
System.out.println("Exited with error code " + exitVal);
|
Logger.print("Exited with error code " + exitVal, this);
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
System.out.println(e.toString());
|
Logger.print(e.toString(), this);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ixab.UserInfoHandling;
|
package com.ixab.UserInfoHandling;
|
||||||
|
|
||||||
import com.ixab.GUI.ErrorMessageGate;
|
import com.ixab.GUI.ErrorMessageGate;
|
||||||
|
import com.ixab.Logging.Logger;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -23,7 +24,7 @@ public class UserInfo {
|
|||||||
try {
|
try {
|
||||||
JSONObject followed = new JSONObject(userFollowData.get(i).toString());
|
JSONObject followed = new JSONObject(userFollowData.get(i).toString());
|
||||||
JSONObject channel = new JSONObject(followed.get("channel").toString());
|
JSONObject channel = new JSONObject(followed.get("channel").toString());
|
||||||
System.out.println(i+" "+channel.get("name").toString()); //remove this line if not needed anymore
|
Logger.print(i + " " + channel.get("name").toString()); //remove this line if not needed anymore
|
||||||
names.add(channel.get("name").toString());
|
names.add(channel.get("name").toString());
|
||||||
// TODO: bisher nur maximal 100 importieren wegen twitch api.
|
// TODO: bisher nur maximal 100 importieren wegen twitch api.
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user