Skip to content

Commit

Permalink
Refine documentation on logging (#8550)
Browse files Browse the repository at this point in the history
* Refine documentation on logging

* Update docs/getting-into-the-code/code-howtos.md

* Update code-howtos.md

* Update tinylog-test.properties

Co-authored-by: Christoph <[email protected]>
  • Loading branch information
koppor and Siedlerchr authored Mar 11, 2022
1 parent 0a22513 commit f033ff3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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
#[email protected] = debug

0 comments on commit f033ff3

Please sign in to comment.