Skip to content

Commit df7326d

Browse files
authored
Merge pull request #9678 from JabRef/reduce-log-noise
Change log level for non-found files during PDF indexing
2 parents 821ff47 + f27797e commit df7326d

File tree

6 files changed

+53
-21
lines changed

6 files changed

+53
-21
lines changed

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
2323
### Changed
2424

2525
- 'Get full text' now also checks the file url. [#568](https://github.com/koppor/jabref/issues/568)
26-
- JabRef writes a new backup file only if there is a change. Before, JabRef created a backup upon start. [#9679](https://github.com/JabRef/jabref/pull/9679)
26+
- We modified the `Add Group` dialog to use the most recently selected group hierarchical context. [#9141](https://github.com/JabRef/jabref/issues/9141)
2727
- We refined the 'main directory not found' error message. [#9625](https://github.com/JabRef/jabref/pull/9625)
28-
- We streamlined the paths for logs and backups: The parent path fragement is always `logs` or `backups`.
28+
- JabRef writes a new backup file only if there is a change. Before, JabRef created a backup upon start. [#9679](https://github.com/JabRef/jabref/pull/9679)
2929
- Backups of libraries are not stored per JabRef version, but collected together.
30-
- We modified the `Add Group` dialog to use the most recently selected group hierarchical context [#9141](https://github.com/JabRef/jabref/issues/9141)
30+
- We streamlined the paths for logs and backups: The parent path fragement is always `logs` or `backups`.
31+
- `log.txt` now contains debug messages. Debugging needs to be enabled explicitly. [#9678](https://github.com/JabRef/jabref/pull/9678)
32+
- `log.txt` does not contain entries for non-found files during PDF indexing. [#9678](https://github.com/JabRef/jabref/pull/9678)
3133
- We improved the Medline importer to correctly import ISO dates for `revised`. [#9536](https://github.com/JabRef/jabref/issues/9536)
3234

3335

docs/code-howtos/logging.md

+37-13
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,44 @@ parent: Code Howtos
55

66
JabRef uses the logging facade [SLF4j](https://www.slf4j.org). All log messages are passed internally to [tinylog](https://tinylog.org/v2/) which handles any filtering, formatting and writing of log messages.
77

8-
* Obtaining a logger for a class:
8+
Obtaining a logger for a class:
99

10-
```java
11-
private static final Logger LOGGER = LoggerFactory.getLogger(<ClassName>.class);
12-
```
10+
```java
11+
private static final Logger LOGGER = LoggerFactory.getLogger(<ClassName>.class);
12+
```
1313

14-
* If the logging event is caused by an exception, please add the exception to the log message as:
14+
Please always use `LOGGER.debug` for debugging.
1515

16-
```java
17-
catch (SomeException e) {
18-
LOGGER.warn("Warning text.", e);
19-
...
20-
}
21-
```
16+
Example:
17+
18+
```java
19+
String example = "example";
20+
LOGGER.debug("Some state {}", example);
21+
```
22+
23+
Enable logging in `tinylog.properties`:
24+
25+
```properties
26+
level@org.jabref.example.ExampleClass = debug
27+
```
28+
29+
If the logging event is caused by an exception, please add the exception to the log message as:
30+
31+
```java
32+
catch (SomeException e) {
33+
LOGGER.warn("Warning text.", e);
34+
...
35+
}
36+
```
37+
38+
When running tests, `tinylog-test.properties` is used.
39+
It is located under `src/test/resources`. As default, only `info` is logged.
40+
When developing, it makes sense to use `debug` as log level.
41+
One can change the log level per class using the pattern `level@class=debug` is set to `debug`.
42+
In the `.properties` file, this is done for `org.jabref.model.entry.BibEntry`.
43+
44+
## Further reading
45+
46+
SLF4J also support parameterized logging, e.g. if you want to print out multiple arguments in a log statement use a pair of curly braces (`{}`).
47+
Head to <https://www.slf4j.org/faq.html#logging_performance> for examples.
2248

23-
* SLF4J also support parameterized logging, e.g. if you want to print out multiple arguments in a log statement use a pair of curly braces. [Examples](https://www.slf4j.org/faq.html#logging\_performance)
24-
* When running tests, `tinylog-test.properties` is used. It is located under `src/test/resources`. As default, only `info` is logged. When developing, it makes sense to use `debug` as log level. One can change the log level per class using the pattern `level@class=debug` is set to `debug`. In the `.properties` file, this is done for `org.jabref.model.entry.BibEntry`.

src/main/java/org/jabref/cli/Launcher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private static void addLogToDisk() {
108108
// https://tinylog.org/v2/configuration/#shared-file-writer
109109
Map<String, String> configuration = Map.of(
110110
"writerFile", "shared file",
111-
"writerFile.level", "info",
111+
"writerFile.level", "debug",
112112
"writerFile.file", directory.resolve("log.txt").toString(),
113113
"writerFile.charset", "UTF-8");
114114

src/main/java/org/jabref/logic/pdf/search/indexing/PdfIndexer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void writeToIndex(BibEntry entry, LinkedFile linkedFile) {
188188
}
189189
Optional<Path> resolvedPath = linkedFile.findIn(databaseContext, filePreferences);
190190
if (resolvedPath.isEmpty()) {
191-
LOGGER.warn("Could not find {}", linkedFile.getLink());
191+
LOGGER.debug("Could not find {}", linkedFile.getLink());
192192
return;
193193
}
194194
try {

src/main/java/org/jabref/model/database/BibDatabaseContext.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,17 @@ public static Path getFulltextIndexBasePath() {
248248

249249
public Path getFulltextIndexPath() {
250250
Path appData = getFulltextIndexBasePath();
251+
Path indexPath;
251252

252253
if (getDatabasePath().isPresent()) {
253-
LOGGER.info("Index path for {} is {}", getDatabasePath().get(), appData);
254-
return appData.resolve(String.valueOf(this.getDatabasePath().get().hashCode()));
254+
indexPath = appData.resolve(String.valueOf(this.getDatabasePath().get().hashCode()));
255+
LOGGER.debug("Index path for {} is {}", getDatabasePath().get(), indexPath);
256+
return indexPath;
255257
}
256258

257-
return appData.resolve("unsaved");
259+
indexPath = appData.resolve("unsaved");
260+
LOGGER.debug("Using index for unsaved database: {}", indexPath);
261+
return indexPath;
258262
}
259263

260264
@Override

src/main/resources/tinylog.properties

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ writerAzure = application insights
55

66
# More shrunk exception logs. See https://tinylog.org/v2/configuration/#strip-stack-trace-elements for details
77
exception = strip: jdk.internal
8+
9+

0 commit comments

Comments
 (0)