[CALCITE-4931] Upgrade SLF4J binding to Log4j2 version 2.15.0

Log4j (binding) is used for testing purposes in various modules and
for production code (shaded) in standalone-server and tck modules.

1. Replace slf4j-log4j12 dependency (using Log4j 1.x)  with
log4j-slf4j-impl (using Log4j 2.x) and take latest version
2. Use XML syntax instead of property syntax for Log4j configuration. A
Log4j configuration is hierarchical by nature so formats with natural
support for nesting (such as XML) are easier to use.

Closes #164

Amending-author: Josh Elser <elserj@apache.org>
diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts
index acbb024..c83801c 100644
--- a/bom/build.gradle.kts
+++ b/bom/build.gradle.kts
@@ -77,6 +77,8 @@
         apiv("org.ow2.asm:asm-tree", "asm")
         apiv("org.ow2.asm:asm-util", "asm")
         apiv("org.slf4j:slf4j-api", "slf4j")
-        apiv("org.slf4j:slf4j-log4j12", "slf4j")
+        // The log4j2 binding should be a runtime dependency but given that
+        // some modules shade this dependency we need to keep it as api
+        apiv("org.apache.logging.log4j:log4j-slf4j-impl", "log4j2")
     }
 }
diff --git a/core/build.gradle.kts b/core/build.gradle.kts
index 1d4a716..607dfe9 100644
--- a/core/build.gradle.kts
+++ b/core/build.gradle.kts
@@ -41,6 +41,7 @@
     testImplementation("junit:junit")
     testImplementation("org.mockito:mockito-core")
     testImplementation("org.hamcrest:hamcrest-core")
+    testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
 }
 
 sourceSets {
diff --git a/core/src/test/resources/log4j.properties b/core/src/test/resources/log4j.properties
deleted file mode 100644
index c961576..0000000
--- a/core/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to you under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Root logger is configured at INFO and is sent to A1
-log4j.rootLogger=INFO, A1
-
-# A1 goes to the console
-log4j.appender.A1=org.apache.log4j.ConsoleAppender
-
-# Set the pattern for each log message
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p - %m%n
diff --git a/gradle.properties b/gradle.properties
index 5de965a..22ce4ed 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -72,6 +72,7 @@
 jetty.version=9.4.44.v20210927
 junit.version=4.12
 kerby.version=1.1.1
+log4j2.version=2.15.0
 mockito.version=2.23.4
 protobuf.version=3.17.1
 scott-data-hsqldb.version=0.1
diff --git a/metrics/build.gradle.kts b/metrics/build.gradle.kts
index 8ac5952..53e1778 100644
--- a/metrics/build.gradle.kts
+++ b/metrics/build.gradle.kts
@@ -24,4 +24,5 @@
     testImplementation("junit:junit")
     testImplementation("org.mockito:mockito-core")
     testImplementation("org.hamcrest:hamcrest-core")
+    testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
 }
diff --git a/metrics/src/test/resources/log4j.properties b/metrics/src/test/resources/log4j.properties
deleted file mode 100644
index c961576..0000000
--- a/metrics/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to you under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Root logger is configured at INFO and is sent to A1
-log4j.rootLogger=INFO, A1
-
-# A1 goes to the console
-log4j.appender.A1=org.apache.log4j.ConsoleAppender
-
-# Set the pattern for each log message
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p - %m%n
diff --git a/server/build.gradle.kts b/server/build.gradle.kts
index a1a48a5..cc628fe 100644
--- a/server/build.gradle.kts
+++ b/server/build.gradle.kts
@@ -47,7 +47,7 @@
     testImplementation("org.mockito:mockito-core")
     testImplementation("org.apache.httpcomponents:httpclient")
     testRuntimeOnly("org.hsqldb:hsqldb")
-    testRuntimeOnly("org.slf4j:slf4j-log4j12")
+    testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
 }
 
 tasks {
diff --git a/server/src/test/resources/log4j.properties b/server/src/test/resources/log4j.properties
deleted file mode 100644
index e127e82..0000000
--- a/server/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to you under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Root logger is configured at INFO and is sent to A1
-log4j.rootLogger=INFO, A1
-
-# A1 goes to the console
-log4j.appender.A1=org.apache.log4j.ConsoleAppender
-
-# Set the pattern for each log message
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p - %m%n
-
-# Debug for JGSS and Jetty's security (Kerberos/SPNEGO debugging)
-#log4j.logger.sun.security.jgss=DEBUG
-#log4j.logger.org.eclipse.jetty.security=DEBUG
diff --git a/server/src/test/resources/log4j2-test.xml b/server/src/test/resources/log4j2-test.xml
new file mode 100644
index 0000000..7a51a2b
--- /dev/null
+++ b/server/src/test/resources/log4j2-test.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to you under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<Configuration>
+  <Appenders>
+    <Console name="A1" target="SYSTEM_OUT">
+      <PatternLayout
+          pattern="%d [%t] %-5p - %m%n"/>
+    </Console>
+  </Appenders>
+
+  <Loggers>
+    <Root level="ERROR">
+      <AppenderRef ref="A1"/>
+    </Root>
+  </Loggers>
+</Configuration>
diff --git a/src/main/config/checkstyle/suppressions.xml b/src/main/config/checkstyle/suppressions.xml
index d335ac7..abb885a 100644
--- a/src/main/config/checkstyle/suppressions.xml
+++ b/src/main/config/checkstyle/suppressions.xml
@@ -44,7 +44,6 @@
   <suppress checks=".*" files="trace.properties"/>
   <suppress checks=".*" files="release.properties"/>
   <suppress checks=".*" files="core[/\\]src[/\\]main[/\\]java[/\\]org[/\\]apache[/\\]calcite[/\\]avatica[/\\]proto"/>
-  <suppress checks=".*" files="log4j.properties"/>
   <suppress checks=".*" files="auth-users.properties"/>
   <suppress checks=".*" files="FilteredConstants.java"/>
 
diff --git a/src/main/config/licenses/slf4j-log4j12/LICENSE b/src/main/config/licenses/slf4j-log4j12/LICENSE
deleted file mode 100644
index 5a11c0c..0000000
--- a/src/main/config/licenses/slf4j-log4j12/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-Copyright (c) 2004-2007 QOS.ch
-All rights reserved.
-
-Permission is hereby granted, free  of charge, to any person obtaining
-a  copy  of this  software  and  associated  documentation files  (the
-"Software"), to  deal in  the Software without  restriction, including
-without limitation  the rights to  use, copy, modify,  merge, publish,
-distribute,  sublicense, and/or sell  copies of  the Software,  and to
-permit persons to whom the Software  is furnished to do so, subject to
-the following conditions:
-
-The  above  copyright  notice  and  this permission  notice  shall  be
-included in all copies or substantial portions of the Software.
-
-THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
-EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
-MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/standalone-server/build.gradle.kts b/standalone-server/build.gradle.kts
index fa9678e..98fbb67 100644
--- a/standalone-server/build.gradle.kts
+++ b/standalone-server/build.gradle.kts
@@ -49,7 +49,7 @@
     shaded("com.beust:jcommander")
 
     shaded("org.slf4j:slf4j-api")
-    shaded("org.slf4j:slf4j-log4j12")
+    shaded("org.apache.logging.log4j:log4j-slf4j-impl")
 }
 
 tasks {
diff --git a/standalone-server/src/main/resources/log4j.properties b/standalone-server/src/main/resources/log4j.properties
deleted file mode 100644
index c8f6c5b..0000000
--- a/standalone-server/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to you under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Root logger is configured at INFO and is sent to A1
-log4j.rootLogger=INFO, A1
-
-# A1 goes to the console
-log4j.appender.A1=org.apache.log4j.ConsoleAppender
-
-# Set the pattern for each log message
-log4j.appender.A1.layout=org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c{2} - %m%n
diff --git a/standalone-server/src/main/resources/log4j2.xml b/standalone-server/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..0e7c9a0
--- /dev/null
+++ b/standalone-server/src/main/resources/log4j2.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to you under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<Configuration>
+  <Appenders>
+    <Console name="A1" target="SYSTEM_OUT">
+      <PatternLayout
+          pattern="%d{ISO8601} [%t] %-5p %c{2} - %m%n"/>
+    </Console>
+  </Appenders>
+
+  <Loggers>
+    <Root level="INFO">
+      <AppenderRef ref="A1"/>
+    </Root>
+  </Loggers>
+</Configuration>
diff --git a/tck/build.gradle.kts b/tck/build.gradle.kts
index 15969ae..4039339 100644
--- a/tck/build.gradle.kts
+++ b/tck/build.gradle.kts
@@ -50,7 +50,7 @@
     // As long as we want to run compatibility checks again 1.6.0, we have to include these because
     // they weren't yet provided by the avatica client jar
     shaded("org.slf4j:slf4j-api")
-    shaded("org.slf4j:slf4j-log4j12")
+    shaded("org.apache.logging.log4j:log4j-slf4j-impl")
 }
 
 tasks {
@@ -92,7 +92,7 @@
             "javax.servlet",
             "junit",
             "net.hydromatic",
-            "org.apache.log4j",
+            "org.apache.logging.log4j",
             "org.eclipse.jetty",
             "org.hamcrest",
             "org.hsqldb",
diff --git a/tck/src/main/resources/log4j.properties b/tck/src/main/resources/log4j.properties
deleted file mode 100644
index 4a8980a..0000000
--- a/tck/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to you under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# Root logger is configured at INFO and is sent to A1
-log4j.rootLogger=INFO, A1
-
-# A1 goes to the console
-log4j.appender.A1=org.apache.calcite.avatica.tck.shaded.org.apache.log4j.ConsoleAppender
-
-# Set the pattern for each log message
-log4j.appender.A1.layout=org.apache.calcite.avatica.tck.shaded.org.apache.log4j.PatternLayout
-log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c{2} - %m%n
diff --git a/tck/src/main/resources/log4j2.xml b/tck/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..0e7c9a0
--- /dev/null
+++ b/tck/src/main/resources/log4j2.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to you under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<Configuration>
+  <Appenders>
+    <Console name="A1" target="SYSTEM_OUT">
+      <PatternLayout
+          pattern="%d{ISO8601} [%t] %-5p %c{2} - %m%n"/>
+    </Console>
+  </Appenders>
+
+  <Loggers>
+    <Root level="INFO">
+      <AppenderRef ref="A1"/>
+    </Root>
+  </Loggers>
+</Configuration>