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

@ -5,7 +5,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.1.4-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View file

@ -17,6 +17,7 @@
package io.bitsquare.app.bootstrap;
import io.bitsquare.app.Logging;
import io.bitsquare.p2p.BootstrapNodes;
import io.bitsquare.p2p.Node;
@ -52,8 +53,10 @@ public class BootstrapNode {
}
public void start() {
String name = env.getRequiredProperty(Node.NAME_KEY);
int port = env.getProperty(Node.PORT_KEY, Integer.class, BootstrapNodes.DEFAULT_PORT);
String name = env.getRequiredProperty(Node.NAME_KEY);
Logging.setup(name + "_" + port);
try {
Number160 peerId = Number160.createHash(name);

View file

@ -23,32 +23,8 @@
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>.bitsquare/bootstrapNode.log</file>
<append>false</append>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>bootstrapNode_%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="INFO">
<appender-ref ref="CONSOLE_APPENDER"/>
<appender-ref ref="FILE"/>
</root>
<logger name="net.tomp2p" level="INFO"/>
<logger name="io.bitsquare" level="INFO"/>
<logger name="org.bitcoinj" level="WARN"/>
<logger name="com.vinumeris.updatefx" level="WARN"/>
</configuration>

View file

@ -6,7 +6,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.1.4-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
@ -145,16 +145,7 @@
<artifactId>gson</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.0.6_20</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.0.0</version>
</dependency>
<dependency>
<groupId>net.glxn</groupId>
<artifactId>qrgen</artifactId>
@ -175,11 +166,6 @@
<artifactId>annotations</artifactId>
<version>13.0</version>
</dependency>
<dependency>
<groupId>eu.hansolo.enzo</groupId>
<artifactId>Enzo</artifactId>
<version>0.1.5</version>
</dependency>
<dependency>
<groupId>org.fxmisc.easybind</groupId>
@ -187,26 +173,6 @@
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.vinumeris</groupId>
<artifactId>updatefx</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--
<dependency>
<groupId>com.vinumeris</groupId>
<artifactId>crashfx-client</artifactId>
<version>1.1</version>
</dependency>
-->
</dependencies>
</project>

View file

@ -0,0 +1,64 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.app;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.core.rolling.FixedWindowRollingPolicy;
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy;
public class Logging {
private static final Logger log = LoggerFactory.getLogger(Logging.class);
public static void setup(String fileName) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender appender = new RollingFileAppender();
appender.setContext(loggerContext);
appender.setFile(fileName + ".log");
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(appender);
rollingPolicy.setFileNamePattern(fileName + "_%i.log");
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(10);
rollingPolicy.start();
SizeBasedTriggeringPolicy triggeringPolicy = new ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy();
triggeringPolicy.setMaxFileSize("1MB");
triggeringPolicy.start();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %xEx%n");
encoder.start();
appender.setEncoder(encoder);
appender.setRollingPolicy(rollingPolicy);
appender.setTriggeringPolicy(triggeringPolicy);
appender.start();
ch.qos.logback.classic.Logger logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
logbackLogger.addAppender(appender);
}
}

View file

@ -0,0 +1,32 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.app;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Version {
private static final Logger log = LoggerFactory.getLogger(Version.class);
public static final int MAJOR_VERSION = 0;
public static final int MINOR_VERSION = 1;
public static final int PATCH_VERSION = 3; // Will be used by UpdatedFX
public static final String VERSION = MAJOR_VERSION + "." + MINOR_VERSION + "." + PATCH_VERSION;
}

View file

@ -82,10 +82,6 @@ public class FileManager<T> {
private final Callable<Void> saver;
private T serializable;
public static void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
FileManager.uncaughtExceptionHandler = uncaughtExceptionHandler;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -100,8 +96,6 @@ public class FileManager<T> {
.setNameFormat("FileManager thread")
.setPriority(Thread.MIN_PRIORITY); // Avoid competing with the GUI thread.
builder.setUncaughtExceptionHandler(uncaughtExceptionHandler);
// An executor that starts up threads when needed and shuts them down later.
this.executor = new ScheduledThreadPoolExecutor(1, builder.build());
this.executor.setKeepAliveTime(5, TimeUnit.SECONDS);

View file

@ -22,7 +22,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>io.bitsquare</groupId>
<version>0.1.4-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -116,5 +116,43 @@
<artifactId>core</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.vinumeris</groupId>
<artifactId>updatefx</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.vinumeris</groupId>
<artifactId>crashfx-client</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>8.0.6_20</version>
</dependency>
<dependency>
<groupId>de.jensd</groupId>
<artifactId>fontawesomefx</artifactId>
<version>8.0.0</version>
</dependency>
<dependency>
<groupId>eu.hansolo.enzo</groupId>
<artifactId>Enzo</artifactId>
<version>0.1.5</version>
</dependency>
</dependencies>
</project>

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"/>

View file

@ -6,7 +6,7 @@
<groupId>io.bitsquare</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>0.1.4-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
<description>The decentralized bitcoin exchange</description>
<url>https://bitsquare.io</url>