-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Learn Log4j in 5 minutes! page
#2556
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
Conversation
ppkarwasz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I have added some notes below.
| * Enhance the output with additional information (timestamp, class & method name, line number, host, severity, etc.) | ||
| * Use different **layouts** (CSV, JSON, etc.) | ||
| * Forward to different **appenders** (file, socket, database, queue, etc.) | ||
| * **Filter** on demand (e.g., increase verbosity dynamically for troubleshooting purposes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming someone doesn't know anything about logging, he doesn't know what a "layout" or "appender" it.
A short description of these might be necessary:
* Write the message in a different way, using a different **layout** (CSV, JSON, etc.)
* Write the message to a different medium, using a different **appender** (file, socket, database, queue, etc.)
* Write only some of the messages, using a **filter** (e.g. filter by severity, content, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a great correction! Applied in fb1f06b.
| ---- | ||
| <1> This is a thread-safe, reusable `Logger` instance. | ||
| The associated class will be captured at initialization – no need for a `getLogger(DbTableService.class)`. | ||
| <2> The generated **log event** will be automatically parameter formatted (note the parameter placeholder, i.e., `{}`) and enriched with **level** (i.e., `WARN`), timestamp, class & method name, line number, and several other information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"parameter formatted" is a little bit technical. What about:
The parameter placeholders `{}` in the message will be automatically replaced with the value of `tableName` and the log event will be enriched with ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 2804621.
|
|
||
| [source,java] | ||
| ---- | ||
| // [✗] `Object#toString()` is redundant in arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the impression that users often don't read the explanation if it is contained in a source code comment. Maybe the rationale should also be written as text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 34c325c. While doing so, learned something called Antora checklists.
| <2> SLF4J is another widely used logging API. | ||
| `log4j-slf4j2-impl` forwards SLF4J calls to Log4j API, which effectively gets processed by Log4j Core too. | ||
|
|
||
| Next, you need a `src/**test**/resources/log4j2.xml`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Next, you need a `src/**test**/resources/log4j2.xml`. | |
| Next, you need a `src/**test**/resources/log4j2-test.xml`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 89f8827.
Fixes #2507.