Skip to content

Commit

Permalink
feat(logging): apache#13378 Uniformly use log4j2 as the logging compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
oxsean committed Nov 19, 2023
1 parent b152e5b commit 233f406
Show file tree
Hide file tree
Showing 156 changed files with 2,647 additions and 847 deletions.
5 changes: 0 additions & 5 deletions dubbo-cluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@
<artifactId>micrometer-tracing-integration-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.logger.Level;
import org.apache.dubbo.common.utils.DubboAppender;
import org.apache.dubbo.common.utils.LogUtil;
import org.apache.dubbo.rpc.AppResponse;
Expand All @@ -34,7 +35,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Level;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down
38 changes: 0 additions & 38 deletions dubbo-cluster/src/test/resources/log4j.xml

This file was deleted.

29 changes: 29 additions & 0 deletions dubbo-cluster/src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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 status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%ex" disableAnsi="false" charset="UTF-8"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
5 changes: 0 additions & 5 deletions dubbo-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,5 @@
<artifactId>cglib-nodep</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.FileAppender;
import org.apache.log4j.spi.LoggingEvent;

public class DubboAppender extends FileAppender {

private static final String DEFAULT_FILE_NAME = "dubbo.log";
public class DubboAppender {

public DubboAppender() {
super();
setFile(DEFAULT_FILE_NAME);
}

public static boolean available = false;
Expand All @@ -47,21 +41,9 @@ public static void clear() {
logList.clear();
}

@Override
public void append(LoggingEvent event) {
super.append(event);
public void append(Log event) {
if (available) {
Log temp = parseLog(event);
logList.add(temp);
logList.add(event);
}
}

private Log parseLog(LoggingEvent event) {
Log log = new Log();
log.setLogName(event.getLogger().getName());
log.setLogLevel(event.getLevel());
log.setLogThread(event.getThreadName());
log.setLogMessage(event.getMessage().toString());
return log;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package org.apache.dubbo.common.utils;

import java.io.Serializable;
import org.apache.dubbo.common.logger.Level;

import org.apache.log4j.Level;
import java.io.Serializable;

public class Log implements Serializable {
private static final long serialVersionUID = -534113138054377073L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.dubbo.common.logger.Level;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Level;

public class LogUtil {

private static final Logger Log = LoggerFactory.getLogger(LogUtil.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ void testCacheContains() throws URISyntaxException {
}

private String getDirectoryOfClassPath() throws URISyntaxException {
URL resource = this.getClass().getResource("/log4j.xml");
URL resource = this.getClass().getResource("/log4j2-test.xml");
String path = Paths.get(resource.toURI()).toFile().getAbsolutePath();
int index = path.indexOf("log4j.xml");
int index = path.indexOf("log4j2-test.xml");
String directoryPath = path.substring(0, index);
return directoryPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ void testFileSizeExceed() throws Exception {
}

private String getDirectoryOfClassPath() throws URISyntaxException {
URL resource = this.getClass().getResource("/log4j.xml");
URL resource = this.getClass().getResource("/log4j2-test.xml");
String path = Paths.get(resource.toURI()).toFile().getAbsolutePath();
int index = path.indexOf("log4j.xml");
int index = path.indexOf("log4j2-test.xml");
String directoryPath = path.substring(0, index);
return directoryPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.log4j.Category;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.dubbo.common.logger.Level;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -29,19 +28,16 @@
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class DubboAppenderTest {
private LoggingEvent event;
private Log event;

@BeforeEach
public void setUp() throws Exception {
event = mock(LoggingEvent.class);
when(event.getLogger()).thenReturn(mock(Category.class));
when(event.getLevel()).thenReturn(mock(Level.class));
when(event.getThreadName()).thenReturn("thread-name");
when(event.getMessage()).thenReturn("message");
event = new Log();
event.setLogLevel(Level.INFO);
event.setLogMessage("message");
event.setLogThread("thread-name");
}

@AfterEach
Expand All @@ -63,7 +59,7 @@ void testAvailable() {
void testAppend() {
DubboAppender appender = new DubboAppender();
appender.append(event);
assumeTrue(0 == DubboAppender.logList.size());
assumeTrue(DubboAppender.logList.isEmpty());
DubboAppender.doStart();
appender.append(event);
assertThat(DubboAppender.logList, hasSize(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.log4j.Level;
import org.apache.dubbo.common.logger.Level;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.log4j.Level;
import org.apache.dubbo.common.logger.Level;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

Expand Down
41 changes: 0 additions & 41 deletions dubbo-common/src/test/resources/log4j.xml

This file was deleted.

29 changes: 29 additions & 0 deletions dubbo-common/src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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 status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%ex" disableAnsi="false" charset="UTF-8"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
4 changes: 2 additions & 2 deletions dubbo-compatible/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<optional>true</optional>
</dependency>
<dependency>
Expand Down
29 changes: 29 additions & 0 deletions dubbo-compatible/src/test/resources/log4j2-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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 status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} %style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} %style{-|}{White} %m%n%ex" disableAnsi="false" charset="UTF-8"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
5 changes: 0 additions & 5 deletions dubbo-config/dubbo-config-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@
<artifactId>zookeeper</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
Expand Down
Loading

0 comments on commit 233f406

Please sign in to comment.