DefaultLogBuilder ignores a throwable inferred by created Message
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- java
- Lĩnh vực
- backend, observability
Hướng nghiên cứu
Bắt đầu từ phương thức logMessage(Message) của DefaultLogBuilder và kiểm tra cách nó truyền throwable tường minh vào logger.logMessage. Tái hiện các ví dụ logger.error và logger.atError().log, sau đó xác minh rằng builder giữ lại throwable được suy luận bởi Message khi không có throwable tường minh nào được thiết lập; lưu ý rằng TestLogger thực hiện suy luận riêng trong phương thức log của nó.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
When using DefaultLogBuilder log* methods, throwable information that might have been inferred by the created Message object is lost - and DefaultLogBuilder only passes the explicit throwable that was set via LogBuilder.withThrowable(Throwable).
This is in contradiction to the regular use of Logger methods that accept message+args - which creates a Message using the configured factory, and then uses Message.getThrowable() to extract the throwable.
This was initially assumed as a bug in log4j-transform-maven-plugin (which converts regular Logger calls to LogBuilder):
https://github.com/apache/logging-log4j-transform/issues/169
but I realized that it might be a stretch for the plugin to infer this data at build-time to be able to pass it to .withThrowable.
Suggested Fix
Change DefaultLogBuilder's logMessage(Message) code
from logger.logMessage(level, marker, fqcn, location, message, throwable);
to logger.logMessage(level, marker, fqcn, location, message, throwable != null ? throwable : message.getThrowable());
Configuration
Version: 2.24.3
Operating system: macOS Sonoma 14.7.2
JDK: eclipse-temurin 17.0.13
Logs
Consider the following code:
Throwable throwable = new Exception("Oh oh");
String messageFormat = "Hello, {}!";
String arg = "Problem";
logger.error(messageFormat, arg, throwable);
logger.atError().log(messageFormat, arg, throwable);
results in the following output:
14:30:53.223 [main] ERROR net.kundas.Main - Hello, Problem!
java.lang.Exception: Oh oh
at net.kundas.Main.main(Main.java:11) [classes/:?]
14:30:53.233 [main] ERROR net.kundas.Main - Hello, Problem!
Reproduction
I've tried recreating it in a unit test, but they seem to be using org.apache.logging.log4j.test.TestLogger, which does this inference in its log method:
final Throwable t;
if (throwable == null
&& params != null
&& params.length > 0
&& params[params.length - 1] instanceof Throwable) {
t = (Throwable) params[params.length - 1];
} else {
t = throwable;
}
if (t != null) {
sb.append(' ');
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
t.printStackTrace(new PrintStream(baos));
sb.append(baos);
}
- Ngôn ngữ chính
- Java
- Star
- 3.6k
- Fork
- 1.8k
- Merge trung bình
- 5 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 24
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/logging-log4j2
-
additivity attributeĐang mởwaiting-for-maintainer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
apache/logging-log4j2#4475 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Migrate `log4j-api-test` tests to JUnit 5Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởapi priority: P3 tests waiting-for-maintainer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
apache/logging-log4j2#4430 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`Rfc5424Layout` does not escape the `newLineEscape` replacement in SD-PARAM-VALUECó thể đã có người làm @lunarbae628 đã nhận 5 ngày trước. Đang mởbug layouts priority: P3
apache/logging-log4j2#4464 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
configuration enhancement layouts
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
apache/logging-log4j2#4463 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`evaluateOnStartup="true"` saves logs under wrong file names after missing scheduled rollCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởappenders:Rolling bug priority: P1 waiting-for-maintainer
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
apache/logging-log4j2#4449 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/logging-log4j2
Issue tương tự
-
[Bug]: Nullable implicit operator on string extensible enums still throws for a null stringCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug emitter:client:csharp
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/typespec#12572 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG]: Java SDK MountRequest always sends update-optional fields, resetting stored mount settingsĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
GCC 15.2: -Wcast-qual warning - cast discards const qualifier from pointer target type (H5trace.c)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] RemotingHelper.connect swaps the socket send and receive buffer configurationCó thể đã có người làm @amalsaidov đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày