Config log to file, add CrashFX (UI side)

This commit is contained in:
Manfred Karrer 2015-04-08 16:24:15 +02:00
parent bea3dbc445
commit 47f7f3b0bb
16 changed files with 169 additions and 171 deletions

View file

@ -22,22 +22,17 @@ import io.bitsquare.gui.common.view.CachingViewLoader;
import io.bitsquare.gui.common.view.View;
import io.bitsquare.gui.common.view.ViewLoader;
import io.bitsquare.gui.common.view.guice.InjectorViewFactory;
import io.bitsquare.gui.components.Popups;
import io.bitsquare.gui.main.MainView;
import io.bitsquare.gui.main.debug.DebugView;
import io.bitsquare.gui.util.ImageUtil;
import io.bitsquare.storage.FileManager;
import io.bitsquare.util.Utilities;
import org.bitcoinj.utils.Threading;
import com.google.common.base.Throwables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import java.io.IOException;
import java.io.InvalidObjectException;
import javafx.application.Application;
import javafx.application.Platform;
@ -48,15 +43,17 @@ import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Logger;
import com.vinumeris.crashfx.CrashFX;
import com.vinumeris.crashfx.CrashWindow;
import org.springframework.core.env.Environment;
import static io.bitsquare.app.BitsquareEnvironment.APP_NAME_KEY;
public class BitsquareApp extends Application {
private static final Logger log = LoggerFactory.getLogger(BitsquareApp.class);
private static final Logger log = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(BitsquareApp.class);
private static Environment env;
@ -72,26 +69,25 @@ public class BitsquareApp extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
this.primaryStage = primaryStage;
log.trace("BitsquareApp.start");
try {
log.trace("BitsquareApp.start");
// Set user thread for callbacks from backend threads
Threading.USER_THREAD = Platform::runLater;
// Use CrashFX for report crash logs
/* CrashFX.setup("Bitsquare/" + Version.VERSION,
Paths.get(env.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY), "crashes"),
URI.create("http://188.226.179.109/crashfx/upload"));*/
// Server not setup yet, so we use client side only support
CrashFX.setup();
// Guice
bitsquareAppModule = new BitsquareAppModule(env, primaryStage);
injector = Guice.createInjector(bitsquareAppModule);
injector.getInstance(InjectorViewFactory.class).setInjector(injector);
FileManager.setUncaughtExceptionHandler(
(t, throwable) -> Platform.runLater(
() -> Popups.handleUncaughtExceptions(Throwables.getRootCause(throwable))
)
);
Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) ->
Popups.handleUncaughtExceptions(Throwables.getRootCause(throwable)));
// load the main view and create the main scene
log.trace("viewLoader.load(MainView.class)");
CachingViewLoader viewLoader = injector.getInstance(CachingViewLoader.class);
View view = viewLoader.load(MainView.class);
@ -100,9 +96,7 @@ public class BitsquareApp extends Application {
"/io/bitsquare/gui/bitsquare.css",
"/io/bitsquare/gui/images.css");
// configure the system tray
SystemTray.create(primaryStage, this::stop);
primaryStage.setOnCloseRequest(e -> {
e.consume();
@ -119,9 +113,7 @@ public class BitsquareApp extends Application {
showDebugWindow();
});
// configure the primary stage
primaryStage.setTitle(env.getRequiredProperty(APP_NAME_KEY));
primaryStage.setScene(scene);
primaryStage.setMinWidth(750);
@ -139,23 +131,17 @@ public class BitsquareApp extends Application {
primaryStage.getIcons().add(new Image(getClass().getResourceAsStream(iconPath)));
// make the UI visible
log.trace("primaryStage.show");
primaryStage.show();
//TODO just temp.
//showDebugWindow();
} catch (Throwable t) {
if (t instanceof InvalidObjectException) {
Popups.openErrorPopup("There is a problem with different version of persisted objects. " +
"Please delete the db directory inside the app directory.");
}
log.error(t.toString());
CrashWindow.open(t);
}
}
//TODO just temp.
private void showDebugWindow() {
ViewLoader viewLoader = injector.getInstance(ViewLoader.class);
View debugView = viewLoader.load(DebugView.class);

View file

@ -53,7 +53,7 @@ public class BitsquareAppEnvironment extends BitsquareEnvironment {
setProperty(APP_NAME_KEY, appName);
setProperty(UserAgent.NAME_KEY, appName);
setProperty(UserAgent.VERSION_KEY, BitsquareAppMain.getVersion());
setProperty(UserAgent.VERSION_KEY, Version.VERSION);
setProperty(WalletService.DIR_KEY, appDataDir);
setProperty(WalletService.PREFIX_KEY, appName);

View file

@ -47,12 +47,6 @@ import static java.util.Arrays.asList;
public class BitsquareAppMain extends BitsquareExecutable {
private static final Logger log = LoggerFactory.getLogger(BitsquareAppMain.class);
private static final String VERSION = "0.1";
public static String getVersion() {
return VERSION + "." + UpdateProcess.getBuildVersion();
}
public static void main(String[] args) throws Exception {
// We don't want to do the full argument parsing here as that might easily change in update versions
// So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
@ -76,6 +70,8 @@ public class BitsquareAppMain extends BitsquareExecutable {
BitsquareAppEnvironment bitsquareEnvironment = new BitsquareAppEnvironment(options);
String updatesDirectory = bitsquareEnvironment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY);
Logging.setup(Paths.get(bitsquareEnvironment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY), "bitsquare").toString());
// app dir need to be setup before UpdateFX bootstrap
initAppDir(updatesDirectory);

View file

@ -47,18 +47,11 @@ import rx.subjects.Subject;
public class UpdateProcess {
private static final Logger log = LoggerFactory.getLogger(UpdateProcess.class);
// Edit version for updateFX
private static final int BUILD_VERSION = 3;
private static final List<ECPoint> UPDATE_SIGNING_KEYS = Crypto.decode("0296CFF54A8B1611499D4C1024E654140AFBB58C505FE4BB7C847B4F4A7C683DF6");
private static final String UPDATES_BASE_URL = "http://bitsquare.io/updateFX/";
private static final int UPDATE_SIGNING_THRESHOLD = 1;
private static final Path ROOT_CLASS_PATH = UpdateFX.findCodePath(BitsquareAppMain.class);
public static int getBuildVersion() {
return BUILD_VERSION;
}
private final Environment environment;
public enum State {
@ -92,7 +85,7 @@ public class UpdateProcess {
}
public void init() {
log.info("UpdateFX current version " + BUILD_VERSION);
log.info("UpdateFX current version " + Version.PATCH_VERSION);
// process.timeout() will cause an error state back but we don't want to break startup in case of an timeout
timeoutTimer = GUIUtil.setTimeout(10000, animationTimer -> {
@ -101,9 +94,9 @@ public class UpdateProcess {
});
timeoutTimer.start();
String agent = environment.getProperty(BitsquareEnvironment.APP_NAME_KEY) + BitsquareAppMain.getVersion();
String agent = environment.getProperty(BitsquareEnvironment.APP_NAME_KEY) + Version.VERSION;
Path dataDirPath = new File(environment.getProperty(BitsquareEnvironment.APP_DATA_DIR_KEY)).toPath();
Updater updater = new Updater(UPDATES_BASE_URL, agent, BUILD_VERSION, dataDirPath, ROOT_CLASS_PATH,
Updater updater = new Updater(UPDATES_BASE_URL, agent, Version.PATCH_VERSION, dataDirPath, ROOT_CLASS_PATH,
UPDATE_SIGNING_KEYS, UPDATE_SIGNING_THRESHOLD) {
@Override
protected void updateProgress(long workDone, long max) {
@ -125,14 +118,14 @@ public class UpdateProcess {
log.info("One liner: {}", summary.descriptions.get(0).getOneLiner());
log.info("{}", summary.descriptions.get(0).getDescription());
}
if (summary.highestVersion > BUILD_VERSION) {
if (summary.highestVersion > Version.PATCH_VERSION) {
log.info("UPDATE_AVAILABLE");
state.set(State.UPDATE_AVAILABLE);
// We stop the timeout and treat it not completed.
// The user should click the restart button manually if there are updates available.
timeoutTimer.stop();
}
else if (summary.highestVersion == BUILD_VERSION) {
else if (summary.highestVersion == Version.PATCH_VERSION) {
log.info("UP_TO_DATE");
state.set(State.UP_TO_DATE);
timeoutTimer.stop();

View file

@ -20,14 +20,9 @@ package io.bitsquare.gui.components;
import io.bitsquare.gui.OverlayManager;
import io.bitsquare.locale.BSResources;
import org.bitcoinj.store.BlockStoreException;
import com.google.common.base.Throwables;
import java.util.ArrayList;
import java.util.List;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.stage.Stage;
@ -213,33 +208,6 @@ public class Popups {
removeBlurContent();
}
// Support handling of uncaught exception from any thread (also non gui thread)
public static void handleUncaughtExceptions(Throwable throwable) {
// while dev
log.error(throwable.getMessage());
log.error(throwable.toString());
throwable.printStackTrace();
Runnable runnable = () -> {
if (Throwables.getRootCause(throwable) instanceof BlockStoreException) {
Popups.openErrorPopup("Error", "Application already running",
"This application is already running and cannot be started twice.\n\n " +
"Check your system tray to reopen the window of the running application.");
Platform.exit();
}
else {
Popups.openExceptionPopup(throwable, "Exception", "A critical error has occurred.",
"Please copy the exception details and open a bug report at:\n " +
"https://github.com/bitsquare/bitsquare/issues.");
Platform.exit();
}
};
if (Platform.isFxApplicationThread())
runnable.run();
else
Platform.runLater(runnable);
}
// custom
public static void openInsufficientMoneyPopup() {

View file

@ -163,7 +163,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
}
@FXML
void createOffer() {
void createOffer() {
if (model.isRegistered()) {
createOfferButton.setDisable(true);
offerActionHandler.createOffer(model.getAmountAsCoin(), model.getPriceAsCoin());

View file

@ -6,26 +6,8 @@
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>.bitsquare/bitsquare.log</file>
<append>false</append>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>.bitsquare_logs/bitsquare_%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>1MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %xEx%n</pattern>
</encoder>
</appender>
<root level="WARN">
<appender-ref ref="CONSOLE_APPENDER"/>
<appender-ref ref="FILE"/>
</root>
<logger name="io.bitsquare" level="TRACE"/>