Skip to content

Commit

Permalink
Add log on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed May 12, 2022
1 parent 69ba879 commit 048729b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

- We added a fetcher for [Biodiversity Heritage Library)](https://www.biodiversitylibrary.org/) [8539](https://github.com/JabRef/jabref/issues/8539)
- We added support for multiple messages in the snackbar. [#7340](https://github.com/JabRef/jabref/issues/7340)
- JabRef now writes log files. Linux: `$home/.cache/jabref/logs/version`, Windows: `%APPDATA%\..\Local\harawata\jabref\version\logs`, Mac: `Users/.../Library/Logs/jabref/version`

### Changed

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/org/jabref/gui/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
import java.util.Map;

import javafx.application.Application;
import javafx.application.Platform;
Expand All @@ -26,15 +27,18 @@
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
import org.jabref.logic.remote.RemotePreferences;
import org.jabref.logic.remote.client.RemoteClient;
import org.jabref.logic.util.BuildInfo;
import org.jabref.migrations.PreferencesMigrations;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

import net.harawata.appdirs.AppDirsFactory;
import org.apache.commons.cli.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tinylog.configuration.Configuration;

/**
* JabRef's main class to process command line options and to start the UI
Expand All @@ -45,10 +49,34 @@ public class JabRefMain extends Application {
private static String[] arguments;

public static void main(String[] args) {
addLogToDisk();
arguments = args;
launch(arguments);
}

/**
* This needs to be called as early as possible. After the first log write, it is not possible to alter
* the log configuration programmatically anymore.
*/
private static void addLogToDisk() {
Path directory = Path.of(AppDirsFactory.getInstance().getUserLogDir(
"jabref",
new BuildInfo().version.toString(),
"org.jabref"));
try {
Files.createDirectories(directory);
} catch (IOException e) {
LOGGER.error("Could not create log directory {}", directory, e);
return;
}
Map<String, String> configuration = Map.of(
"writerFile", "rolling file",
"writerFile.level", "info",
"writerFile.file", directory.resolve("log_{count}.txt").toString(),
"writerFile.latest", directory.resolve("latest.txt").toString());
Configuration.replace(configuration);
}

@Override
public void start(Stage mainStage) {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/tinylog.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ level = info
writer = gui
writer1 = console
writer2 = application insights

exception = strip: jdk.internal

0 comments on commit 048729b

Please sign in to comment.