Skip to content

Commit

Permalink
Since there were calls to the logger before we even knew where to sto…
Browse files Browse the repository at this point in the history
…re the logfile, we always created an empty undefined log file in the current working directory. (#45)

Now we activate the logging on the preloader and activate it explicitly by using the system property.

Co-authored-by: Markus <[email protected]>
  • Loading branch information
fisch3r and fisch3r authored May 20, 2020
1 parent 3494670 commit 95ea923
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
32 changes: 2 additions & 30 deletions src/main/java/org/correomqtt/CorreoMqtt.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.correomqtt;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
Expand All @@ -15,11 +11,7 @@
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.correomqtt.business.dispatcher.ApplicationLifecycleDispatcher;
import org.correomqtt.business.dispatcher.PreloadingDispatcher;
import org.correomqtt.business.dispatcher.ShortcutDispatcher;
import org.correomqtt.business.dispatcher.StartupDispatcher;
import org.correomqtt.business.dispatcher.StartupObserver;
import org.correomqtt.business.dispatcher.*;
import org.correomqtt.business.model.SettingsDTO;
import org.correomqtt.business.services.ConfigService;
import org.correomqtt.business.utils.VersionUtils;
Expand Down Expand Up @@ -60,10 +52,9 @@ public void init() throws IOException {
final SettingsDTO settings = ConfigService.getInstance().getSettings();

handleVersionMismatch(settings);

setLocale(settings);
HostServicesHolder.getInstance().setHostServices(getHostServices());
setLoggerFilePath();

PreloadingDispatcher.getInstance().onProgress(resources.getString("preloaderLanguageSet"));

if (settings.isFirstStart()) {
Expand Down Expand Up @@ -193,25 +184,6 @@ private void setupShortcut() {
);
}

private void setLoggerFilePath() {

// Set the path for file logging to user directory.
System.setProperty("correomqtt-logfile", ConfigService.getInstance().getLogPath());

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
ContextInitializer ci = new ContextInitializer(lc);
lc.reset();
try {
//I prefer autoConfig() over JoranConfigurator.doConfigure() so I wouldn't need to find the file myself.
ci.autoConfig();
} catch (JoranException e) {
// StatusPrinter will try to log this
e.printStackTrace(); //TODO
}
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}


@Override
public void onPluginUpdateFailed(String disabledPath) {
AlertHelper.warn(
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/correomqtt/CorreoPreloader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.correomqtt;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.RotateTransition;
Expand All @@ -17,6 +21,7 @@
import org.correomqtt.business.services.ConfigService;
import org.correomqtt.business.utils.VersionUtils;
import org.correomqtt.gui.controller.PreloaderViewController;
import org.slf4j.LoggerFactory;

import java.io.IOException;

Expand All @@ -32,6 +37,8 @@ public CorreoPreloader() {

@Override
public void init() throws IOException {
setLoggerFilePath();

ConfigService.getInstance().setCssFileName();
String cssPath = ConfigService.getInstance().getCssPath();

Expand All @@ -47,6 +54,24 @@ public void init() throws IOException {
}
}

private void setLoggerFilePath() {
// Set the path for file logging to user directory.
System.setProperty("correomqtt-logfile", ConfigService.getInstance().getLogPath());
System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, CorreoMqtt.class.getResource("logger-config.xml").getPath());

LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
ContextInitializer ci = new ContextInitializer(lc);
lc.reset();
try {
//I prefer autoConfig() over JoranConfigurator.doConfigure() so I wouldn't need to find the file myself.
ci.autoConfig();
} catch (JoranException e) {
// StatusPrinter will try to log this
e.printStackTrace(); //TODO
}
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}

@Override
public void start(Stage primaryStage) throws Exception {
this.preloaderStage = primaryStage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.correomqtt.plugin.manager;

import org.slf4j.LoggerFactory;

import java.io.FilePermission;
import java.lang.reflect.ReflectPermission;
import java.security.*;
Expand Down Expand Up @@ -45,8 +43,6 @@ public static Permissions removeForbiddenPermissions(String pluginName, Permissi
Permission p = permissionIterator.next();
if (isPermissionAllowed(p)) {
cleanPermissions.add(p);
} else {
LoggerFactory.getLogger(PluginSecurityPolicy.class).warn("{} tried to add forbidden permission: {}", pluginName, p);
}
}
return cleanPermissions;
Expand Down
File renamed without changes.

0 comments on commit 95ea923

Please sign in to comment.