Skip to content
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

Issue 23631 create global log4j #23964

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

spbolton
Copy link
Contributor

@spbolton spbolton commented Jan 31, 2023

Updated pull request from #23632 Issue #23631 Enable log configuration by setting environment variable USE_GLOBAL_LOG4J=true

Default logging config found in log4j2/conf/log4j2-tomcat.xml

bin/setclasspath.sh or bin/setclasspath.bat contains logic to setup

if [ "$USE_GLOBAL_LOG4J" = true ]; then
echo Using Global Log4j
CLASSPATH="$CATALINA_HOME/log4j2/lib/*:$CATALINA_HOME/log4j2/conf$CLASSPATH"
JAVA_OPTS=" -DLog4jContextSelector=org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector $JAVA_OPTS"
JAVA_OPTS=" -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager $JAVA_OPTS"
fi

default Context selector creates a new context per Classloader and requires separate configuration for each. BasicContextSelection keeps the same context and configuration for all Classloaders, for each there is an Async version that makes all the loggers asynchronous and improves performance.

The log4j jars have been added to $CATALINA_HOME/log4j2/lib to support slf4j, commons-logging, Jul logging log4j 1. A log4j2-appserver jar is set up to replace the standard tomcat logging. Although the log4j2-appserver replaces the jul logging in tomcat directly Some plugin code uses java.util.logging and the LogManger needs to be set to pass this logging back to log4j.

By default the logfile is picked up from the classpath and found in CATALINA_HOME/log4j2/conf see

https://logging.apache.org/log4j/2.x/log4j-appserver/index.html

The log file could be specified with a jvm option -Dlog4j.configurationFile=path/to/log4j2.xml or map the file/folder in docker.

Read configuration guide https://logging.apache.org/log4j/2.x/manual/configuration.html on how to modify the config,https://logging.apache.org/log4j/2.x/manual/configuration.html It is currently set to only log to stdout. for docker.

@github-actions
Copy link

github-actions bot commented Jan 31, 2023

Unit Tests Report

1 418 tests  ±0   1 408 ✔️ ±0   3m 47s ⏱️ -15s
   140 suites ±0        10 💤 ±0 
   140 files   ±0          0 ±0 

Results for commit aa5f866. ± Comparison against base commit adfff75.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 31, 2023

Postman Tests Report

0 files   -      54  0 suites   - 733   0s ⏱️ - 1h 31m 11s
0 tests  -    362  0 ✔️  -    361  0 💤 ±0  0  - 1 
0 runs   - 1 118  0 ✔️  - 1 113  0 💤 ±0  0  - 5 

Results for commit c0b488f. ± Comparison against base commit 9d691ee.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 31, 2023

Integration Tests [postgres] Report

   408 files   -   1     408 suites   - 1   58m 59s ⏱️ - 10m 16s
3 878 tests  - 14  3 734 ✔️  - 134  23 💤 ±0  121 +120 
3 900 runs   - 13  3 755 ✔️  - 134  23 💤 ±0  122 +121 

For more details on these failures, see this check.

Results for commit aa5f866. ± Comparison against base commit adfff75.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 31, 2023

Integration Tests [mssql] Report

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ±0 

Results for commit aa5f866. ± Comparison against base commit adfff75.

♻️ This comment has been updated with latest results.

@spbolton spbolton force-pushed the issue-23631-create-global-log4j-int1 branch from 2bb3864 to 5a9ecd5 Compare February 3, 2023 02:56
@spbolton spbolton force-pushed the issue-23631-create-global-log4j-int1 branch from ab55184 to 66e3d46 Compare February 3, 2023 22:12
@spbolton spbolton force-pushed the issue-23631-create-global-log4j-int1 branch from c13fd20 to ef29177 Compare February 7, 2023 01:41
@dotcms-sonarqube
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition C Reliability Rating on New Code (is worse than A)
Failed condition 14.9% 14.92% Coverage on New Code (is less than 80%)

See analysis details on SonarQube

Fix issues before they fail your Quality Gate with SonarLint SonarLint in your IDE.

@github-actions
Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Mar 10, 2023
@github-actions
Copy link

This PR was closed because it has been stalled with no activity.

@github-actions github-actions bot closed this Mar 18, 2023
@spbolton spbolton reopened this Jul 10, 2024
@spbolton spbolton requested a review from a team as a code owner July 10, 2024 14:54
@spbolton spbolton removed the stale label Jul 10, 2024
.recordStats()
.expireAfter(new Expiry<String, Object>() {
public long expireAfterCreate(String key, Object value, long currentTime) {
long ttlInSeconds;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can avoid an else by setting Long.MAX_VALUE here

size = Config.getIntProperty("cache." + DEFAULT_CACHE + ".size", 100);
if(value instanceof Expirable
&& ((Expirable) value).getTtl() > 0) {
ttlInSeconds = ((Expirable) value).getTtl();
Copy link
Contributor

Choose a reason for hiding this comment

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

my personal preference is to use Expirable.cast(value).getTtl()

@@ -88,6 +88,29 @@ public boolean areRecordsLeftToIndex() throws DotDataException {
public long recordsInQueue() throws DotDataException {
return recordsInQueue(DbConnectionFactory.getConnection());
}

@Override
public boolean waitForEmptyQueue(int maxWaitSeconds) throws DotDataException {
Copy link
Contributor

Choose a reason for hiding this comment

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

set param to final

// This should be replaced with a more efficient solution that uses a notification mechanism
// but that would require a more complex implementation and this is required for some tests currently
try {
long recordsInQueue = recordsInQueue();
Copy link
Contributor

Choose a reason for hiding this comment

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

this is ok, but wondering if we cannot eventually change this kind of infinite stuff to Stream or Iterable

@@ -269,6 +281,14 @@ public static boolean connectionExists() {
return isCreated;
} // connectionExists.

public static Optional<Throwable> getCreatorStack() {
Copy link
Contributor

Choose a reason for hiding this comment

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

doc it is a public method

@@ -269,6 +281,14 @@ public static boolean connectionExists() {
return isCreated;
} // connectionExists.

public static Optional<Throwable> getCreatorStack() {
if (connectionExists()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

my preference is one line return return connectionExists()? Optional.ofNullable(creatorStack.get()): Optional.empty();

@@ -457,6 +492,10 @@ public static void closeConnection(String ds) {

}

public static void setConnectionLogger(boolean connectionLogger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

doc me

Copy link
Contributor

Choose a reason for hiding this comment

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

set arg to final

/**
* Attempts to find a session associated with the Thread. If there isn't a
* session, it will create one.
*/
public static Session getSession() {
public static Session getSession(boolean createIfClosed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

set to final arg

props.setProperty(key, value);
}
}

public static Map<String,String> getOverrides() {
Copy link
Contributor

Choose a reason for hiding this comment

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

docme

return Map.copyOf(testOverrideTracker);
}

public static Map<String,String> compareOverrides(Map<String,String> before) {
Copy link
Contributor

Choose a reason for hiding this comment

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

doc me and set to final the arg

}

public static Map<String,String> compareOverrides(Map<String,String> before) {
Map<String,String> after = getOverrides();
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting method, I think it would be a good candidate to CollectionUtils

@spbolton spbolton marked this pull request as draft September 9, 2024 12:06
@nollymar nollymar changed the base branch from master to main September 30, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants