forked from apache/rocketmq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Author: 鲁般 <[email protected]> Closes apache#120 from lindzh/fix_client_logger.
- Loading branch information
Showing
6 changed files
with
158 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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. | ||
--> | ||
|
||
<!DOCTYPE xml> | ||
<Configuration status="warn" name="RocketmqClient"> | ||
<Appenders> | ||
<Console name="STDOUT-APPENDER"> | ||
<PatternLayout pattern="%-5p %c{2} , %m%n"/> | ||
</Console> | ||
<RollingFile name="RocketmqClientAppender" fileName="${sys:client.logRoot}/rocketmq_client.log" | ||
filePattern="${sys:client.logRoot}/rocketmq_client-%d{yyyy-MM-dd}-%i.log"> | ||
<PatternLayout pattern="%d{yyy-MM-dd HH\:mm\:ss,SSS} %p %c{1}(%L) - %m%n"/> | ||
<Policies> | ||
<TimeBasedTriggeringPolicy/> | ||
<SizeBasedTriggeringPolicy size="1 GB"/> | ||
</Policies> | ||
<DefaultRolloverStrategy max="${sys:client.logFileMaxIndex}"/> | ||
</RollingFile> | ||
</Appenders> | ||
<Loggers> | ||
<logger name="RocketmqClient" level="${sys:client.logLevel}" additivity="false"> | ||
<appender-ref ref="RocketmqClientAppender"/> | ||
</logger> | ||
|
||
<logger name="RocketmqCommon" level="${sys:client.logLevel}" additivity="false"> | ||
<appender-ref ref="RocketmqClientAppender"/> | ||
</logger> | ||
|
||
<logger name="RocketmqRemoting" level="${sys:client.logLevel}" additivity="false"> | ||
<appender-ref ref="RocketmqClientAppender"/> | ||
</logger> | ||
</Loggers> | ||
</Configuration> |
72 changes: 72 additions & 0 deletions
72
client/src/test/java/org/apache/rocketmq/client/log/ClientLogTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.rocketmq.client.log; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.*; | ||
import java.lang.reflect.Field; | ||
import java.util.Date; | ||
|
||
public class ClientLogTest { | ||
|
||
public static final String CLIENT_LOG_ROOT = "rocketmq.client.logRoot"; | ||
public static final String LOG_DIR; | ||
|
||
static { | ||
LOG_DIR = System.getProperty(CLIENT_LOG_ROOT, "${user.home}/logs/rocketmqlogs"); | ||
} | ||
|
||
// FIXME: Workarond for concret implementation for slf4j, is there any better solution for all slf4j implementations in one class ? 2017/8/1 | ||
@Test | ||
public void testLog4j2() throws IOException, NoSuchFieldException, IllegalAccessException { | ||
ClientLogger.getLog(); | ||
long seek = 0; | ||
boolean result = false; | ||
File file = new File(LOG_DIR + File.separator + "rocketmq_client.log"); | ||
if (file.exists()) { | ||
seek = file.length(); | ||
} | ||
Field logClassField = ClientLogger.class.getDeclaredField("logClass"); | ||
logClassField.setAccessible(true); | ||
Class logClass = (Class) logClassField.get(ClientLogger.class); | ||
Assert.assertEquals("org.apache.logging.slf4j.Log4jLoggerFactory", logClass.getName()); | ||
for (int i = 0; i < 10; i++) { | ||
ClientLogger.getLog().info("testcase testLog4j2 " + new Date()); | ||
} | ||
|
||
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); | ||
randomAccessFile.seek(seek); | ||
String line = randomAccessFile.readLine(); | ||
int idx = 1; | ||
while (line != null) { | ||
if (line.contains("testLog4j2")) { | ||
result = true; | ||
break; | ||
} | ||
line = randomAccessFile.readLine(); | ||
idx++; | ||
if (idx > 20) { | ||
break; | ||
} | ||
} | ||
randomAccessFile.close(); | ||
Assert.assertTrue(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters