Skip to content

Conversation

@vy
Copy link
Member

@vy vy commented May 1, 2024

Fixes #2507.

@vy vy added the documentation Pull requests or issues that affect documentation label May 1, 2024
@vy vy requested a review from ppkarwasz May 1, 2024 14:48
@vy vy self-assigned this May 1, 2024
Copy link
Contributor

@ppkarwasz ppkarwasz left a 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.

Comment on lines 40 to 43
* 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)
Copy link
Contributor

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

Copy link
Member Author

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.
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Next, you need a `src/**test**/resources/log4j2.xml`.
Next, you need a `src/**test**/resources/log4j2-test.xml`.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 89f8827.

@vy vy merged commit d352ec5 into 2.x May 2, 2024
@vy vy deleted the doc/2.x/5min branch May 2, 2024 06:56
vy added a commit that referenced this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Pull requests or issues that affect documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a Learn Log4j in under 2 minutes! page

2 participants