Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change log level for non-found files during PDF indexing #9678

Merged
merged 5 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

- 'Get full text' now also checks the file url. [#568](https://github.com/koppor/jabref/issues/568)
- We refined the 'main directory not found' error message. [#9625](https://github.com/JabRef/jabref/pull/9625)
- `log.txt` now contains debug messages. Debugging needs to be enabled explicitly. [#9678](https://github.com/JabRef/jabref/pull/9678)
- `log.txt` does not contain entries for non-found files during PDF indexing. [#9678](https://github.com/JabRef/jabref/pull/9678)
- We modified the `Add Group` dialog to use the most recently selected group hierarchical context [#9141](https://github.com/JabRef/jabref/issues/9141)


Expand Down
50 changes: 37 additions & 13 deletions docs/code-howtos/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,44 @@ parent: Code Howtos

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.

* Obtaining a logger for a class:
Obtaining a logger for a class:

```java
private static final Logger LOGGER = LoggerFactory.getLogger(<ClassName>.class);
```
```java
private static final Logger LOGGER = LoggerFactory.getLogger(<ClassName>.class);
```

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

```java
catch (SomeException e) {
LOGGER.warn("Warning text.", e);
...
}
```
Example:

```java
String example = "example";
LOGGER.debug("Some state {}", example);
```

Enable logging in `tinylog.properties`:

```properties
[email protected] = debug
```

If the logging event is caused by an exception, please add the exception to the log message as:

```java
catch (SomeException e) {
LOGGER.warn("Warning text.", e);
...
}
```

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`.

## Further reading

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 (`{}`).
Head to <https://www.slf4j.org/faq.html#logging_performance> for examples.

* 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)
* 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`.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/cli/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static void addLogToDisk() {
// https://tinylog.org/v2/configuration/#shared-file-writer
Map<String, String> configuration = Map.of(
"writerFile", "shared file",
"writerFile.level", "info",
"writerFile.level", "debug",
"writerFile.file", directory.resolve("log.txt").toString(),
"writerFile.charset", "UTF-8");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void writeToIndex(BibEntry entry, LinkedFile linkedFile) {
}
Optional<Path> resolvedPath = linkedFile.findIn(databaseContext, filePreferences);
if (resolvedPath.isEmpty()) {
LOGGER.warn("Could not find {}", linkedFile.getLink());
LOGGER.debug("Could not find {}", linkedFile.getLink());
return;
}
try {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/jabref/model/database/BibDatabaseContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,17 @@ public static Path getFulltextIndexBasePath() {

public Path getFulltextIndexPath() {
Path appData = getFulltextIndexBasePath();
Path indexPath;

if (getDatabasePath().isPresent()) {
LOGGER.info("Index path for {} is {}", getDatabasePath().get(), appData);
return appData.resolve(String.valueOf(this.getDatabasePath().get().hashCode()));
indexPath = appData.resolve(String.valueOf(this.getDatabasePath().get().hashCode()));
LOGGER.debug("Index path for {} is {}", getDatabasePath().get(), indexPath);
return indexPath;
}

return appData.resolve("unsaved");
indexPath = appData.resolve("unsaved");
LOGGER.debug("Using index for unsaved database: {}", indexPath);
return indexPath;
}

@Override
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 @@ -5,3 +5,5 @@ writerAzure = application insights

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

#[email protected] = debug