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

Refine documentation on logging #8550

Merged
merged 4 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions docs/getting-into-the-code/code-howtos.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Please read [https://github.com/cxxr/better-java](https://github.com/cxxr/better

Principles:

* All Exceptions we throw should be or extend `JabRefException`; This is especially important if the message stored in the Exception should be shown to the user. `JabRefException` has already implemented the `getLocalizedMessage()` method which should be used for such cases \(see details below!\).
* All exceptions we throw should be or extend `JabRefException`; This is especially important if the message stored in the Exception should be shown to the user. `JabRefException` has already implemented the `getLocalizedMessage()` method which should be used for such cases \(see details below!\).
* Catch and wrap all API exceptions \(such as `IOExceptions`\) and rethrow them
* Example:

Expand Down Expand Up @@ -119,7 +119,8 @@ If you want to catch the event you'll have to register your listener class with

## Logging

JabRef uses the logging facade [SLF4j](https://www.slf4j.org/). All log messages are passed internally to [log4j2](https://logging.apache.org/log4j/2.x/) which handles any filtering, formatting and writing of log messages.
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:

Expand All @@ -137,6 +138,11 @@ JabRef uses the logging facade [SLF4j](https://www.slf4j.org/). All log messages
```

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

## Using Localization correctly

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ private Optional<String> genericGetFieldOrAlias(Field field, BiFunction<BibEntry
}
} else {
// Date field not in valid format
LOGGER.debug("Could not parse date " + date.get());
LOGGER.debug("Could not parse date {}", date.get());
return Optional.empty();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/tinylog-test.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
level = info
writer = console
# uncomment the following line to enable debug logging outputs
#level@org.jabref.model.entry.BibEntry = debug