-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the priority of multiple log-conf.xml with the same namespace. (
#12) * Support the priority of multiple log-conf.xml with the same namespace.And the lowest priority is `zero`
- Loading branch information
1 parent
2e312c7
commit 4f6abfa
Showing
8 changed files
with
225 additions
and
17 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
56 changes: 56 additions & 0 deletions
56
src/test/java/com/alipay/sofa/common/log/factory/LoggerSpaceOverrideUsageTest.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,56 @@ | ||
/* | ||
* 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 com.alipay.sofa.common.log.factory; | ||
|
||
import com.alipay.sofa.common.log.SpaceInfo; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">GengZhang</a> | ||
*/ | ||
public class LoggerSpaceOverrideUsageTest { | ||
|
||
@Test | ||
public void testGetResource() throws IOException { | ||
LoggerSpaceFactory4LogbackBuilder builder = new LoggerSpaceFactory4LogbackBuilder( | ||
new SpaceInfo()); | ||
ClassLoader classLoader = LoggerSpaceOverrideUsageTest.class.getClassLoader(); | ||
|
||
Assert.assertNull(builder.getResource(classLoader, null)); | ||
|
||
List<URL> configFileUrls = new ArrayList<URL>(); | ||
Assert.assertNull(builder.getResource(classLoader, configFileUrls)); | ||
|
||
URL url1 = classLoader.getResource("com/alipay/sofa/testover1/log/log4j/log-conf.xml"); | ||
configFileUrls.add(url1); | ||
Assert.assertEquals(url1, builder.getResource(classLoader, configFileUrls)); | ||
|
||
URL url2 = classLoader.getResource("com/alipay/sofa/testover2/log/log4j/log-conf.xml"); | ||
configFileUrls.add(url2); | ||
Assert.assertEquals(url2, builder.getResource(classLoader, configFileUrls)); | ||
|
||
URL url3 = classLoader.getResource("com/alipay/sofa/testover3/log/log4j/log-conf.xml"); | ||
configFileUrls.add(url3); | ||
Assert.assertEquals(url2, builder.getResource(classLoader, configFileUrls)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/resources/com/alipay/sofa/testover1/log/log4j/log-conf.xml
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE log4j:configuration SYSTEM "http://toolkit.alibaba-inc.com/dtd/log4j/log4j.dtd"> | ||
|
||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
|
||
<appender name="ROOT-APPENDER" class="org.apache.log4j.DailyRollingFileAppender"> | ||
<param name="file" value="${logging.test.path}/${appname}/common-default.log"/> | ||
<param name="append" value="true"/> | ||
<param name="threshold" value="${info}"/> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%d %-5p %-32t - %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<root> | ||
<level value="info"/> | ||
<appender-ref ref="ROOT-APPENDER"/> | ||
</root> | ||
|
||
</log4j:configuration> |
1 change: 1 addition & 0 deletions
1
src/test/resources/com/alipay/sofa/testover2/log/log4j/config.properties
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 @@ | ||
priority=200 |
20 changes: 20 additions & 0 deletions
20
src/test/resources/com/alipay/sofa/testover2/log/log4j/log-conf.xml
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE log4j:configuration SYSTEM "http://toolkit.alibaba-inc.com/dtd/log4j/log4j.dtd"> | ||
|
||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
|
||
<appender name="ROOT-APPENDER" class="org.apache.log4j.DailyRollingFileAppender"> | ||
<param name="file" value="${logging.test.path}/${appname}/common-default.log"/> | ||
<param name="append" value="true"/> | ||
<param name="threshold" value="${info}"/> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%d %-5p %-32t - %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<root> | ||
<level value="debug"/> | ||
<appender-ref ref="ROOT-APPENDER"/> | ||
</root> | ||
|
||
</log4j:configuration> |
1 change: 1 addition & 0 deletions
1
src/test/resources/com/alipay/sofa/testover3/log/log4j/config.properties
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 @@ | ||
priority=100 |
20 changes: 20 additions & 0 deletions
20
src/test/resources/com/alipay/sofa/testover3/log/log4j/log-conf.xml
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!DOCTYPE log4j:configuration SYSTEM "http://toolkit.alibaba-inc.com/dtd/log4j/log4j.dtd"> | ||
|
||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
|
||
<appender name="ROOT-APPENDER" class="org.apache.log4j.DailyRollingFileAppender"> | ||
<param name="file" value="${logging.test.path}/${appname}/common-default.log"/> | ||
<param name="append" value="true"/> | ||
<param name="threshold" value="${info}"/> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%d %-5p %-32t - %m%n"/> | ||
</layout> | ||
</appender> | ||
|
||
<root> | ||
<level value="debug"/> | ||
<appender-ref ref="ROOT-APPENDER"/> | ||
</root> | ||
|
||
</log4j:configuration> |