Skip to content

Commit

Permalink
add logfile to support package
Browse files Browse the repository at this point in the history
  • Loading branch information
jixxed committed Aug 23, 2024
1 parent 7a5c313 commit 3e753a6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ The auto updaters will check for a new version on launch.
The portable zip versions are used as update packages. You can run them standalone, but they are no longer truly portable as settings are stored on the local machine.

**Release notes for this version:**
Bugfix for determining whether the app is registered for edomh:// urls
Add logfile to support package
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package nl.jixxed.eliteodysseymaterials;

import io.sentry.Attachment;
import io.sentry.Sentry;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.core.logging.SLF4JLogDelegateFactory;
import lombok.extern.slf4j.Slf4j;
import nl.jixxed.eliteodysseymaterials.constants.OsConstants;
import nl.jixxed.eliteodysseymaterials.domain.ApplicationState;
import nl.jixxed.eliteodysseymaterials.service.SupportService;

import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -42,6 +44,19 @@ public static void main(final String[] args) {
options.setEnvironment(getEnvironment(buildVersion));
options.setRelease("edomh-app@" + buildVersion);
options.setEnabled(!buildVersion.equals("dev"));
options.setBeforeSend((event, hint) -> {
String supportFile = "";
try {
supportFile = SupportService.createSupportPackage();
} catch (Exception e) {
log.error("Failed to create support package", e);
}
if(!supportFile.isBlank()) {
Attachment attachment = new Attachment(supportFile);
hint.addAttachment(attachment);
}
return event;
});
});
FXApplication.launchFx(args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package nl.jixxed.eliteodysseymaterials.service;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender;
import ch.qos.logback.core.rolling.RollingFileAppender;
import lombok.extern.slf4j.Slf4j;
import nl.jixxed.eliteodysseymaterials.constants.AppConstants;
import nl.jixxed.eliteodysseymaterials.constants.OsConstants;
import nl.jixxed.eliteodysseymaterials.constants.PreferenceConstants;
import nl.jixxed.eliteodysseymaterials.domain.ApplicationState;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -16,6 +22,7 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Iterator;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
Expand All @@ -34,22 +41,22 @@ public static String createSupportPackage(String name) {
Path journalFolder = Path.of(PreferencesService.getPreference(PreferenceConstants.JOURNAL_FOLDER, OsConstants.DEFAULT_WATCHED_FOLDER));
try {
log.info("Creating support package.");
return zipFolder(configFolder, journalFolder, supportFolder,backupFolder, name);
return zipFolder(configFolder, journalFolder, supportFolder, backupFolder, name);
} catch (Exception e) {
log.error("Failed to create support package.", e);
}
return "";
}

private static String zipFolder(Path configFolderPath,Path journalFolderPath, Path zipPath, Path backupFolderPath,String name) throws Exception {
private static String zipFolder(Path configFolderPath, Path journalFolderPath, Path zipPath, Path backupFolderPath, String name) throws Exception {
final String filename = name != null ? name : "support." + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss.SSS").format(LocalDateTime.now());
File backupFile = new File(zipPath.toFile().getAbsoluteFile() + "/" + filename + ".zip");
Files.deleteIfExists(backupFile.toPath());
zipPath.toFile().mkdirs();
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(backupFile))) {
Files.walkFileTree(configFolderPath, new SimpleFileVisitor<>() {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (!file.startsWith(zipPath) &&!file.startsWith(backupFolderPath) && !isExcluded(file.getFileName().toString())) {
if (!file.startsWith(zipPath) && !file.startsWith(backupFolderPath) && !isExcluded(file.getFileName().toString())) {
zos.putNextEntry(new ZipEntry(configFolderPath.relativize(file).toString()));
log.debug("support: " + file.getFileName());
Files.copy(file, zos);
Expand All @@ -65,18 +72,19 @@ private boolean isExcluded(String fileName) {

Files.walkFileTree(journalFolderPath, new SimpleFileVisitor<>() {
List<String> files = List.of(
AppConstants.CARGO_FILE,
AppConstants.BACKPACK_FILE,
AppConstants.FCMATERIALS_FILE,
AppConstants.STATUS_FILE,
AppConstants.SHIPLOCKER_FILE,
AppConstants.SHIPYARD_FILE,
AppConstants.OUTFITTING_FILE,
AppConstants.MARKET_FILE,
AppConstants.NAVROUTE_FILE,
AppConstants.MODULESINFO_FILE,
ApplicationState.getInstance().getWatchedFile()
AppConstants.CARGO_FILE,
AppConstants.BACKPACK_FILE,
AppConstants.FCMATERIALS_FILE,
AppConstants.STATUS_FILE,
AppConstants.SHIPLOCKER_FILE,
AppConstants.SHIPYARD_FILE,
AppConstants.OUTFITTING_FILE,
AppConstants.MARKET_FILE,
AppConstants.NAVROUTE_FILE,
AppConstants.MODULESINFO_FILE,
ApplicationState.getInstance().getWatchedFile()
);

public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (files.contains(file.getFileName().toString())) {
zos.putNextEntry(new ZipEntry("journal/" + journalFolderPath.relativize(file).toString()));
Expand All @@ -87,7 +95,35 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
return FileVisitResult.CONTINUE;
}
});
File logFile = findLogFile();
if(logFile != null && logFile.exists()) {
zos.putNextEntry(new ZipEntry("log/edomh.log"));
log.debug("support: " + logFile.getName());
Files.copy(Path.of(logFile.getAbsolutePath()), zos);
zos.closeEntry();
}
}
return backupFile.getAbsolutePath();
}

private static File findLogFile() {
File clientLogFile;
RollingFileAppender<?> fileAppender = null;
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
for (Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders();
index.hasNext(); ) {
Object enumElement = index.next();
if (enumElement instanceof RollingFileAppender<?>) {
fileAppender = (RollingFileAppender<?>) enumElement;
}
}
}
if (fileAppender != null) {
clientLogFile = new File(fileAppender.getFile());
} else {
clientLogFile = null;
}
return clientLogFile;
}
}
4 changes: 4 additions & 0 deletions application/src/main/resources/text/whatsnew.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 2.103
-------------
Add logfile to support package

Version 2.102
-------------
Bugfix for registering edomh:// urls
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.parallel=true
org.gradle.caching=true
version=2.102
version=2.103

0 comments on commit 3e753a6

Please sign in to comment.