-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make StatusLogger
self-contained and testable
#2249
Conversation
I will go through this as I can. It might take a couple of days depending on my available time. However, the description of the solution above seems to aim right on target. |
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.
This looks almost ready.
Remark the PropertiesUtil.Environment
does not log anything about broken property sources to prevent a recursive initialization. Now we can start logging again.
log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/UsingStatusLoggerMock.java
Outdated
Show resolved
Hide resolved
log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/package-info.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Outdated
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Show resolved
Hide resolved
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Outdated
Show resolved
Hide resolved
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 like this approach so far!
@ppkarwasz, I have introduced the fallback listener concept back in cd3fadb. Would you mind reviewing it, please? |
log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/StatusLoggerAdmin.java
Outdated
Show resolved
Hide resolved
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
This reverts commit f3fa918.
`announce@apache.org` requires the sender to have an `@apache.org` address. Not all PMC members have this configured, this adds yet another step to the release process and yet another condition to hold in the RM machine, and people are not willing to drop this requirement[1]. [1] https://lists.apache.org/thread/jc7o25gxx9w3y3xq51kwbmcbz62cwkb2
As per discussion[1], nested logging is not an official feature. Hence, when it is broken, the build should not fail. [1] https://lists.apache.org/thread/gnwjw7sfhxogb7c70rqr4t0v6yh4px02
Nested logging is not an officially supported feature[1]. Tests should not rely on them. [1] https://lists.apache.org/thread/gnwjw7sfhxogb7c70rqr4t0v6yh4px02
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
Show resolved
Hide resolved
StatusLogger
self-contained and testableStatusLogger
self-contained and testable
Hi, It will cause a StackOverflowError such as:
which is caused by
because in org.apache.logging.log4j.status.StatusLogger.Config#readInstantFormatter, the code is merely logging-log4j2/log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java Lines 252 to 255 in f05864d
with only DateTimeFormatter.ofPattern(format) This works on Java 11, but on Java 8, it breaks as in https://stackoverflow.com/questions/25229124/unsupportedtemporaltypeexception-when-formatting-instant-to-string A very simple fix is to use instead private static DateTimeFormatter readInstantFormatter(final Properties fileProvidedProperties) {
final String format = readProperty(fileProvidedProperties, STATUS_DATE_FORMAT);
return format != null ? DateTimeFormatter.ofPattern(format).withZone(ZoneId.systemDefault()) : null;
} Hence using |
@lauredogit, thanks so much for the report. I will submit a fix. We are considering a |
Perfect, thanks! I think there are 2 distinct issues at play. The easy one to fix is the actual UnsupportedTemporalTypeException on Java 8, which will be fixed easily by adding the ".withZone(ZoneId.systemDefault())". However, the other issue is that having such an exception thrown by the StatusLogger was causing a StackOverflowError... This can be investigated later on, though. |
Well, logMessageTrackRecursion only tracks recursion, it doesn't do anything about it. Other parts of the system like async logger read the recursion level (and log synchronously for example). |
Motivated by #2204 and making
log4j-api-2.x
adaptable by Log4j 3, this work revamps theStatusLogger
to make it self-contained and testable. Noteworthy changes are as follows:Simplifications and improvements for self-contained implementation
PropertiesUtil
andLoaderUtil
are eliminated. To do so, simple system property and resource from classpath readers are implemented. See the newStatusLogger.Config
class.SimpleLogger
is eliminated. The default listener is fixed to aStatusConsoleListener
which dumpsStatusData#getFormattedStatus()
output to aPrintStream
.StatusConfiguration
does not create a newStatusListener
each time anymore. That is, there will not be a dedicatedStatusConsoleListener
for every eachLoggerContext
. Existing behaviour was already problematic:StatusConfiguration
created was resetting theStatusLogger
listener level (hence, last one always wins)StatusConsoleListener
s weren't cleaned upLoggerContext
, there is always a singleStatusLogger
, defeating the purpose of per-LoggerContext
listenersStatusConsoleListener
for theStatusLogger
singleton. If user overrides theStatusLogger
configuration in alog4j2.xml
, last read configuration will be the effective one.StatusLogger
javadocs are rewritten.LowLevelLogUtil
is removed.AbstractLogger
doesn't act onlog4j2.messageFactory
andlog4j2.flowMessageFactory
properties anymore; its message and flow message factories are fixed toParameterizedMessageFactory
andDefaultFlowMessageFactory
, respectively. This was necessary to avoid cyclic instantiation:PropertiesUtil
is usingStatusLogger
, which extendsAbstractLogger
, which indirectly reaches back toPropertiesUtil
for these two functionalities removed.Testing-related changes
StatusLogger
is made extendable (to enable mocking/spying)StatusLogger
static instance is made replaceable (to enable substituting the implementation for tests)@UsingStatusLoggerMock
introducedTODO
log4j2.messageFactory
andlog4j2.flowMessageFactory
properties back@UsingStatusListener
Review kit
o.a.l.l.status
package:StatusLogger
,StatusData
,StatusConsoleListener
, etc.StatusConfiguration
o.a.l.l.test.junit.StatusLoggerMockExtension
to see testing conveniences