Skip to content

Commit 048729b

Browse files
committed
Add log on disk
1 parent 69ba879 commit 048729b

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
1313

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

1718
### Changed
1819

src/main/java/org/jabref/gui/JabRefMain.java

+28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.nio.file.Files;
88
import java.nio.file.Path;
99
import java.util.Comparator;
10+
import java.util.Map;
1011

1112
import javafx.application.Application;
1213
import javafx.application.Platform;
@@ -26,15 +27,18 @@
2627
import org.jabref.logic.protectedterms.ProtectedTermsLoader;
2728
import org.jabref.logic.remote.RemotePreferences;
2829
import org.jabref.logic.remote.client.RemoteClient;
30+
import org.jabref.logic.util.BuildInfo;
2931
import org.jabref.migrations.PreferencesMigrations;
3032
import org.jabref.model.database.BibDatabaseContext;
3133
import org.jabref.model.database.BibDatabaseMode;
3234
import org.jabref.preferences.JabRefPreferences;
3335
import org.jabref.preferences.PreferencesService;
3436

37+
import net.harawata.appdirs.AppDirsFactory;
3538
import org.apache.commons.cli.ParseException;
3639
import org.slf4j.Logger;
3740
import org.slf4j.LoggerFactory;
41+
import org.tinylog.configuration.Configuration;
3842

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

4751
public static void main(String[] args) {
52+
addLogToDisk();
4853
arguments = args;
4954
launch(arguments);
5055
}
5156

57+
/**
58+
* This needs to be called as early as possible. After the first log write, it is not possible to alter
59+
* the log configuration programmatically anymore.
60+
*/
61+
private static void addLogToDisk() {
62+
Path directory = Path.of(AppDirsFactory.getInstance().getUserLogDir(
63+
"jabref",
64+
new BuildInfo().version.toString(),
65+
"org.jabref"));
66+
try {
67+
Files.createDirectories(directory);
68+
} catch (IOException e) {
69+
LOGGER.error("Could not create log directory {}", directory, e);
70+
return;
71+
}
72+
Map<String, String> configuration = Map.of(
73+
"writerFile", "rolling file",
74+
"writerFile.level", "info",
75+
"writerFile.file", directory.resolve("log_{count}.txt").toString(),
76+
"writerFile.latest", directory.resolve("latest.txt").toString());
77+
Configuration.replace(configuration);
78+
}
79+
5280
@Override
5381
public void start(Stage mainStage) {
5482
try {

src/main/resources/tinylog.properties

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ level = info
22
writer = gui
33
writer1 = console
44
writer2 = application insights
5+
6+
exception = strip: jdk.internal

0 commit comments

Comments
 (0)