You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by rg...@apache.org on 2010/05/13 08:31:09 UTC
svn commit: r943816 [8/9] - in
/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: ./ log4j12-api/
log4j12-api/src/ log4j12-api/src/main/ log4j12-api/src/main/java/
log4j12-api/src/main/java/org/ log4j12-api/src/main/java/org/apache/
log4j12-api/sr...
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/LICENSE?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/LICENSE (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/LICENSE Thu May 13 06:31:04 2010
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed 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.
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/NOTICE?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/NOTICE (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/NOTICE Thu May 13 06:31:04 2010
@@ -0,0 +1,5 @@
+Apache log4j Enhanced PatternLayout for log4j 1.2.x
+Copyright 2007 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/log4j-provider.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/log4j-provider.xml?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/log4j-provider.xml (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/resources/META-INF/log4j-provider.xml Thu May 13 06:31:04 2010
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+ <entry key="LoggerContextClass">org.apache.logging.log4j.core.LoggerContext</entry>
+ <entry key="Log4jAPIVersion">1.99.0</entry>
+</properties>
\ No newline at end of file
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/css/site.css
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/css/site.css?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/css/site.css (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/css/site.css Thu May 13 06:31:04 2010
@@ -0,0 +1 @@
+
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/images/logo.jpg
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/images/logo.jpg?rev=943816&view=auto
==============================================================================
Binary file - no diff available.
Propchange: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/images/logo.jpg
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/images/ls-logo.jpg
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/images/ls-logo.jpg?rev=943816&view=auto
==============================================================================
Binary file - no diff available.
Propchange: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/images/ls-logo.jpg
------------------------------------------------------------------------------
svn:executable = *
Propchange: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/resources/images/ls-logo.jpg
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/site.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/site.xml?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/site.xml (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/site/site.xml Thu May 13 06:31:04 2010
@@ -0,0 +1,36 @@
+<!--
+ 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.
+
+-->
+<project name="Component">
+ <bannerLeft>
+ <name>Logging Services</name>
+ <src>images/ls-logo.jpg</src>
+ <href>http://logging.apache.org/</href>
+ </bannerLeft>
+ <bannerRight>
+ <src>images/logo.jpg</src>
+ </bannerRight>
+ <body>
+ <links>
+ <item name="Apache" href="http://www.apache.org/" />
+ <item name="Logging Services" href="http://logging.apache.org/"/>
+ <item name="Log4j" href="http://logging.apache.org/log4j/"/>
+ <item name="Log4j Companions" href="http://logging.apache.org/log4j/companions"/>
+ </links>
+ <menu ref="reports"/>
+ </body>
+</project>
\ No newline at end of file
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java Thu May 13 06:31:04 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.logging.log4j.core;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.BaseConfiguration;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+
+/**
+ *
+ */
+public class BasicConfigurationFactory extends ConfigurationFactory {
+
+ public Configuration getConfiguration() {
+ return new BasicConfiguration();
+ }
+
+ public class BasicConfiguration extends BaseConfiguration {
+
+ private static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
+
+ public BasicConfiguration() {
+
+ LoggerConfig root = getRootLogger();
+ String l = System.getProperty(DEFAULT_LEVEL);
+ Level level = (l != null && Level.valueOf(l) != null) ? Level.valueOf(l) : Level.ERROR;
+ root.setLevel(level);
+ }
+}
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java Thu May 13 06:31:04 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.logging.log4j.core;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.internal.StatusLogger;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class SimplePerfTest {
+
+ private static org.apache.logging.log4j.Logger logger = LogManager.getLogger(SimplePerfTest.class.getName());
+ private volatile Level lvl = Level.DEBUG;
+ private static final int LOOP_CNT = 100000000;
+
+ @Test
+ public void debugDisabled() {
+ Timer timer = new Timer("DebugDisabled", LOOP_CNT);
+ timer.start();
+ for (int i=0; i < LOOP_CNT; ++i) {
+ logger.isDebugEnabled();
+ }
+ timer.stop();
+ System.out.println(timer.toString());
+ }
+
+ @Test
+ public void debugLogger() {
+ Timer timer = new Timer("DebugLogger", LOOP_CNT);
+ timer.start();
+ for (int i=0; i < LOOP_CNT; ++i) {
+ logger.debug("This is a test");
+ }
+ timer.stop();
+ System.out.println(timer.toString());
+ }
+ /*
+ @Test
+ public void errorLogger() {
+ Timer timer = new Timer("ErrorLogger", 10);
+ timer.start();
+ for (int i=0; i < 10; ++i) {
+ logger.error("This is a test");
+ }
+ timer.stop();
+ System.out.println(timer.toString());
+ } */
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/ThreadedPerfTest.java Thu May 13 06:31:04 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.logging.log4j.core;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.junit.Test;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ *
+ */
+public class ThreadedPerfTest {
+
+ private static org.apache.logging.log4j.Logger logger = LogManager.getLogger(ThreadedPerfTest.class.getName());
+ private volatile Level lvl = Level.DEBUG;
+ private static final int LOOP_CNT = 10000000;
+ private static final int THREADS = 10;
+
+ @Test
+ public void debugDisabled() {
+ Timer timer = new Timer("DebugDisabled", LOOP_CNT * THREADS);
+ Runnable runnable = new DebugDisabledRunnable();
+ ExecutorService pool = Executors.newFixedThreadPool(THREADS);
+ timer.start();
+ for (int i=0; i < THREADS; ++i) {
+ pool.execute(runnable);
+ }
+ pool.shutdown();
+ timer.stop();
+ System.out.println(timer.toString());
+ }
+
+ @Test
+ public void debugLogger() {
+ Timer timer = new Timer("DebugLogger", LOOP_CNT * THREADS);
+ Runnable runnable = new DebugLoggerRunnable();
+ ExecutorService pool = Executors.newFixedThreadPool(THREADS);
+ timer.start();
+ for (int i=0; i < THREADS; ++i) {
+ pool.execute(runnable);
+ }
+ pool.shutdown();
+ timer.stop();
+ System.out.println(timer.toString());
+ }
+
+ public class DebugDisabledRunnable implements Runnable {
+ public void run() {
+ for (int i=0; i < LOOP_CNT; ++i) {
+ logger.isDebugEnabled();
+ }
+ }
+ }
+
+ public class DebugLoggerRunnable implements Runnable {
+ public void run() {
+ for (int i=0; i < LOOP_CNT; ++i) {
+ logger.debug("This is a test");
+ }
+ }
+ }
+}
\ No newline at end of file
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/Timer.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/Timer.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/Timer.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/Timer.java Thu May 13 06:31:04 2010
@@ -0,0 +1,252 @@
+/*
+ * 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.logging.log4j.core;
+
+import java.io.Serializable;
+import java.text.DecimalFormat;
+
+/**
+ *
+ */
+public class Timer implements Serializable
+{
+ private String m_name; // The timer's name
+ private String m_status; // The timer's status
+ private long m_startTime; // The start time
+ private long m_elapsedTime; // The elapsed time
+ private int m_iterations;
+ private static long NANO_PER_SECOND = 1000000000L;
+ private static long NANO_PER_MINUTE = NANO_PER_SECOND * 60;
+ private static long NANO_PER_HOUR = NANO_PER_MINUTE * 60;
+
+
+ /**
+ * Constructor.
+ * @param name the timer name.
+ */
+ public Timer(String name)
+ {
+ this(name, 0);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param name the timer name.
+ */
+ public Timer(String name, int iterations)
+ {
+ m_name = name;
+ m_startTime = 0;
+ m_status = "Stopped";
+ m_iterations = (iterations > 0) ? iterations : 0;
+ }
+
+ /**
+ * Start the timer.
+ */
+ public void start()
+ {
+ m_startTime = System.nanoTime();
+ m_elapsedTime = 0;
+ m_status = "Start";
+ }
+
+ /**
+ * Stop the timer.
+ */
+ public void stop()
+ {
+ m_elapsedTime += System.nanoTime() - m_startTime;
+ m_startTime = 0;
+ m_status = "Stop";
+ }
+
+ /**
+ * Pause the timer.
+ */
+ public void pause()
+ {
+ m_elapsedTime += System.nanoTime() - m_startTime;
+ m_startTime = 0;
+ m_status = "Pause";
+ }
+
+ /**
+ * Resume the timer.
+ */
+ public void resume()
+ {
+ m_startTime = System.nanoTime();
+ m_status = "Resume";
+ }
+
+ /**
+ * Accessor for the name.
+ * @return the timer's name.
+ */
+ public String getName()
+ {
+ return m_name;
+ }
+
+ /**
+ * Access the elapsed time.
+ *
+ * @return the elapsed time.
+ */
+ public long getElapsedTime()
+ {
+ return m_elapsedTime / 1000000;
+ }
+
+ /**
+ * Access the elapsed time.
+ *
+ * @return the elapsed time.
+ */
+ public long getElapsedNanoTime()
+ {
+ return m_elapsedTime;
+ }
+
+ /**
+ * Return the name of the last operation performed on this timer (Start, Stop, Pause or
+ * Resume).
+ * @return the string representing the last operation performed.
+ */
+ public String getStatus()
+ {
+ return m_status;
+ }
+
+ /**
+ * Return the String representation of the timer based upon its current state
+ */
+ public String toString()
+ {
+ StringBuilder result = new StringBuilder("Timer ").append(m_name);
+ if (m_status.equals("Start"))
+ {
+ result.append(" started");
+ }
+ else if (m_status.equals("Pause"))
+ {
+ result.append(" paused");
+ }
+ else if (m_status.equals("Resume"))
+ {
+ result.append(" resumed");
+ }
+ else if (m_status.equals("Stop"))
+ {
+ long nanoseconds = m_elapsedTime;
+ // Get elapsed hours
+ long hours = nanoseconds / NANO_PER_HOUR;
+ // Get remaining nanoseconds
+ nanoseconds = nanoseconds % NANO_PER_HOUR;
+ // Get minutes
+ long minutes = nanoseconds / NANO_PER_MINUTE;
+ // Get remaining nanoseconds
+ nanoseconds = nanoseconds % NANO_PER_MINUTE;
+ // Get seconds
+ long seconds = nanoseconds / NANO_PER_SECOND;
+ // Get remaining nanoseconds
+ nanoseconds = nanoseconds % NANO_PER_SECOND;
+
+ String elapsed = "";
+
+ if (hours > 0)
+ {
+ elapsed += hours + " hours ";
+ }
+ if (minutes > 0 || hours > 0)
+ {
+ elapsed += minutes + " minutes ";
+ }
+
+ DecimalFormat numFormat = null;
+ numFormat = new DecimalFormat("#0");
+ elapsed += numFormat.format(seconds) + ".";
+ numFormat = new DecimalFormat("000000000");
+ elapsed += numFormat.format(nanoseconds) + " seconds";
+ result.append(" stopped. Elapsed time: ").append(elapsed);
+ if (m_iterations > 0)
+ {
+ nanoseconds = m_elapsedTime / m_iterations;
+ // Get elapsed hours
+ hours = nanoseconds / NANO_PER_HOUR;
+ // Get remaining nanoseconds
+ nanoseconds = nanoseconds % NANO_PER_HOUR;
+ // Get minutes
+ minutes = nanoseconds / NANO_PER_MINUTE;
+ // Get remaining nanoseconds
+ nanoseconds = nanoseconds % NANO_PER_MINUTE;
+ // Get seconds
+ seconds = nanoseconds / NANO_PER_SECOND;
+ // Get remaining nanoseconds
+ nanoseconds = nanoseconds % NANO_PER_SECOND;
+
+ elapsed = "";
+
+ if (hours > 0)
+ {
+ elapsed += hours + " hours ";
+ }
+ if (minutes > 0 || hours > 0)
+ {
+ elapsed += minutes + " minutes ";
+ }
+
+ numFormat = new DecimalFormat("#0");
+ elapsed += numFormat.format(seconds) + ".";
+ numFormat = new DecimalFormat("000000000");
+ elapsed += numFormat.format(nanoseconds) + " seconds";
+ result.append(" Average per iteration: ").append(elapsed);
+ }
+ }
+ else
+ {
+ result.append(" ").append(m_status);
+ }
+ return result.toString();
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Timer)) return false;
+
+ final Timer timer = (Timer) o;
+
+ if (m_elapsedTime != timer.m_elapsedTime) return false;
+ if (m_startTime != timer.m_startTime) return false;
+ if (m_name != null ? !m_name.equals(timer.m_name) : timer.m_name != null) return false;
+ if (m_status != null ? !m_status.equals(timer.m_status) : timer.m_status != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (m_name != null ? m_name.hashCode() : 0);
+ result = 29 * result + (m_status != null ? m_status.hashCode() : 0);
+ result = 29 * result + (int) (m_startTime ^ (m_startTime >>> 32));
+ result = 29 * result + (int) (m_elapsedTime ^ (m_elapsedTime >>> 32));
+ return result;
+ }
+
+}
\ No newline at end of file
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java Thu May 13 06:31:04 2010
@@ -0,0 +1,93 @@
+/*
+ * 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.logging.log4j.core.config;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.filter.MDCFilter;
+import org.apache.logging.log4j.internal.StatusData;
+import org.apache.logging.log4j.internal.StatusLogger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+public class XMLConfigurationTest {
+
+ private static final String CONFIG = "log4j-test1.xml";
+
+ @BeforeClass
+ public static void setupClass() {
+ System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Configuration config = ctx.getConfiguration();
+ if (config instanceof XMLConfiguration) {
+ String name = ((XMLConfiguration) config).getName();
+ if (name == null || !name.equals("XMLConfigTest")) {
+ ctx.reconfigure();
+ }
+ } else {
+ ctx.reconfigure();
+ }
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ ctx.reconfigure();
+ StatusLogger.getLogger().reset();
+ }
+
+ @Test
+ public void testLogger() {
+ Logger logger = LogManager.getLogger("org.apache.logging.log4j.test1.Test");
+ assertTrue(logger instanceof org.apache.logging.log4j.core.Logger);
+ org.apache.logging.log4j.core.Logger l = (org.apache.logging.log4j.core.Logger) logger;
+ assertTrue(l.getLevel().equals(Level.DEBUG));
+ List<Filter> filters = l.getFilters();
+ assertTrue("number of filters - " + filters.size(), filters.size() == 1);
+ Filter filter = filters.get(0);
+ assertTrue(filter instanceof MDCFilter);
+ Map<String, Appender> appenders = l.getAppenders();
+ assertNotNull(appenders);
+ assertTrue("number of appenders = " + appenders.size(), appenders.size() == 1);
+ Appender a = appenders.get("STDOUT");
+ assertNotNull(a);
+ assertEquals(a.getName(), "STDOUT");
+ }
+
+ @Test
+ public void logToFile() {
+ Logger logger = LogManager.getLogger("org.apache.logging.log4j.test2.Test");
+ logger.debug("This is a test");
+ }
+
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java Thu May 13 06:31:04 2010
@@ -0,0 +1,129 @@
+/*
+ * 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.logging.log4j.core.layout;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.MDC;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.BasicConfigurationFactory;
+import org.apache.logging.log4j.core.appender.FileAppender;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+import org.apache.logging.log4j.core.util.Compare;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.FileOutputStream;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class PatternLayoutTest {
+ static String OUTPUT_FILE = "output/PatternParser";
+ static String WITNESS_FILE = "witness/PatternParser";
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("");
+
+ static String msgPattern = "%m%n";
+ static ConfigurationFactory cf = new BasicConfigurationFactory();
+
+ @BeforeClass
+ public static void setupClass() {
+ ConfigurationFactory.setConfigurationFactory(cf);
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ ctx.reconfigure();
+ }
+
+ @AfterClass
+ public static void cleanupClass() {
+ ConfigurationFactory.removeConfigurationFactory(cf);
+ }
+
+
+ /**
+ * Test case for MDC conversion pattern.
+ */
+ @Test
+ public void mdcPattern() throws Exception {
+
+ String mdcMsgPattern1 = "%m : %X%n";
+ String mdcMsgPattern2 = "%m : %X{key1}%n";
+ String mdcMsgPattern3 = "%m : %X{key2}%n";
+ String mdcMsgPattern4 = "%m : %X{key3}%n";
+ String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
+
+ // set up appender
+ PatternLayout layout = new PatternLayout(msgPattern);
+ FileOutputStream fos = new FileOutputStream(OUTPUT_FILE + "_mdc");
+ Appender appender = new FileAppender("File", layout, fos, OUTPUT_FILE + "_mdc");
+ appender.start();
+
+ // set appender on root and set level to debug
+ root.addAppender(appender);
+ root.setLevel(Level.DEBUG);
+
+ // output starting message
+ root.debug("starting mdc pattern test");
+
+ layout.setConversionPattern(mdcMsgPattern1);
+ root.debug("empty mdc, no key specified in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern2);
+ root.debug("empty mdc, key1 in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern3);
+ root.debug("empty mdc, key2 in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern4);
+ root.debug("empty mdc, key3 in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern5);
+ root.debug("empty mdc, key1, key2, and key3 in pattern");
+
+ MDC.put("key1", "value1");
+ MDC.put("key2", "value2");
+
+ layout.setConversionPattern(mdcMsgPattern1);
+ root.debug("filled mdc, no key specified in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern2);
+ root.debug("filled mdc, key1 in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern3);
+ root.debug("filled mdc, key2 in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern4);
+ root.debug("filled mdc, key3 in pattern");
+
+ layout.setConversionPattern(mdcMsgPattern5);
+ root.debug("filled mdc, key1, key2, and key3 in pattern");
+
+ MDC.remove("key1");
+ MDC.remove("key2");
+
+ layout.setConversionPattern(msgPattern);
+ root.debug("finished mdc pattern test");
+
+ assertTrue(Compare.compare(this.getClass(), OUTPUT_FILE + "_mdc", WITNESS_FILE + "_mdc"));
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/pattern/PatternParserTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/pattern/PatternParserTest.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/pattern/PatternParserTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/pattern/PatternParserTest.java Thu May 13 06:31:04 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.logging.log4j.core.layout.pattern;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.MDC;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.FileAppender;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.util.Compare;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Assert;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.FileOutputStream;
+import java.util.List;
+
+/**
+ *
+ */
+public class PatternParserTest {
+
+ static String OUTPUT_FILE = "output/PatternParser";
+ static String WITNESS_FILE = "witness/PatternParser";
+ LoggerContext ctx = (LoggerContext) LogManager.getContext();
+ Logger root = ctx.getLogger("");
+
+ private static String msgPattern = "%m%n";
+ private String mdcMsgPattern1 = "%m : %X%n";
+ private String mdcMsgPattern2 = "%m : %X{key1}%n";
+ private String mdcMsgPattern3 = "%m : %X{key2}%n";
+ private String mdcMsgPattern4 = "%m : %X{key3}%n";
+ private String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
+
+
+ private static final String KEY = "Converter";
+ private PatternParser parser;
+
+ @Before
+ public void setup() {
+ parser = new PatternParser(KEY);
+ }
+
+ private void validateConverter(List<PatternConverter> converters, int index, String name) {
+ PatternConverter pc = converters.get(index);
+ assertEquals("Incorrect converter " + pc.getName() + " at index " + index + " expected " + name,
+ pc.getName(), name);
+ }
+
+ /**
+ * Test the default pattern
+ */
+ @Test
+ public void defaultPattern() {
+ List<PatternConverter> converters = parser.parse(msgPattern);
+ assertNotNull(converters);
+ assertTrue(converters.size() == 2);
+ validateConverter(converters, 0, "Message");
+ validateConverter(converters, 1, "Line Sep");
+ }
+
+
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteDateAndTimeFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteDateAndTimeFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteDateAndTimeFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteDateAndTimeFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+
+public class AbsoluteDateAndTimeFilter implements Filter {
+ Perl5Util util = new Perl5Util();
+
+ public String filter(String in) {
+ String pat = "/" + Filter.ABSOLUTE_DATE_AND_TIME_PAT + "/";
+
+ if (util.match(pat, in)) {
+ return util.substitute(
+ "s/" + Filter.ABSOLUTE_DATE_AND_TIME_PAT + "//", in);
+ } else {
+ return in;
+ }
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteTimeFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteTimeFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteTimeFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/AbsoluteTimeFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+public class AbsoluteTimeFilter implements Filter {
+ Perl5Util util = new Perl5Util();
+
+ public String filter(String in) {
+ String pat = "/" + Filter.ABSOLUTE_TIME_PAT + "/";
+
+ if (util.match(pat, in)) {
+ return util.substitute("s/" + Filter.ABSOLUTE_TIME_PAT + "//", in);
+ } else {
+ return in;
+ }
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Compare.java Thu May 13 06:31:04 2010
@@ -0,0 +1,140 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import java.io.BufferedReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.*;
+import java.net.URL;
+
+
+public class Compare {
+ static final int B1_NULL = -1;
+ static final int B2_NULL = -2;
+
+ private static final InputStream open(
+ final Class testClass,
+ final String fileName) throws IOException {
+ String resourceName = fileName;
+ /* if (fileName.startsWith("witness/")) {
+ resourceName = fileName.substring(fileName.lastIndexOf('/') + 1);
+ } */
+ InputStream is = testClass.getResourceAsStream(resourceName);
+ if (is == null) {
+ is = testClass.getClassLoader().getResourceAsStream(resourceName);
+ }
+ if (is == null) {
+ File file = new File(fileName);
+ if (file.exists()) {
+ is = new FileInputStream(file);
+ } else {
+ throw new FileNotFoundException("Resource "
+ + resourceName + " not found");
+ }
+ }
+ return is;
+ }
+
+ public static boolean compare(Class testClass,
+ final String file1,
+ final String file2)
+ throws IOException {
+ BufferedReader in1 = new BufferedReader(new FileReader(file1));
+ BufferedReader in2 = new BufferedReader(new InputStreamReader(
+ open(testClass, file2)));
+ try {
+ return compare(testClass, file1, file2, in1, in2);
+ } finally {
+ in1.close();
+ in2.close();
+ }
+ }
+
+ public static boolean compare(
+ Class testClass, String file1, String file2, BufferedReader in1, BufferedReader in2) throws IOException {
+
+ String s1;
+ int lineCounter = 0;
+
+ while ((s1 = in1.readLine()) != null) {
+ lineCounter++;
+
+ String s2 = in2.readLine();
+
+ if (!s1.equals(s2)) {
+ System.out.println(
+ "Files [" + file1 + "] and [" + file2 + "] differ on line "
+ + lineCounter);
+ System.out.println("One reads: [" + s1 + "].");
+ System.out.println("Other reads:[" + s2 + "].");
+ outputFile(testClass, file1);
+ outputFile(testClass, file2);
+
+ return false;
+ }
+ }
+
+ // the second file is longer
+ if (in2.read() != -1) {
+ System.out.println(
+ "File [" + file2 + "] longer than file [" + file1 + "].");
+ outputFile(testClass, file1);
+ outputFile(testClass, file2);
+
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Prints file on the console.
+ */
+ private static void outputFile(Class testClass, String file)
+ throws IOException {
+ InputStream is = open(testClass, file);
+ BufferedReader in1 = new BufferedReader(new InputStreamReader(is));
+
+ String s1;
+ int lineCounter = 0;
+ System.out.println("--------------------------------");
+ System.out.println("Contents of " + file + ":");
+
+ while ((s1 = in1.readLine()) != null) {
+ lineCounter++;
+ System.out.print(lineCounter);
+
+ if (lineCounter < 10) {
+ System.out.print(" : ");
+ } else if (lineCounter < 100) {
+ System.out.print(" : ");
+ } else if (lineCounter < 1000) {
+ System.out.print(" : ");
+ } else {
+ System.out.print(": ");
+ }
+
+ System.out.println(s1);
+ }
+ in1.close();
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ControlFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ControlFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ControlFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ControlFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+
+public class ControlFilter implements Filter {
+ Perl5Util util = new Perl5Util();
+ String[] allowedPatterns;
+
+ public ControlFilter(String[] allowedPatterns) {
+ this.allowedPatterns = allowedPatterns;
+ }
+
+ public String filter(String in) throws UnexpectedFormatException {
+ int len = allowedPatterns.length;
+
+ for (int i = 0; i < len; i++) {
+ //System.out.println("["+allowedPatterns[i]+"]");
+ if (util.match("/" + allowedPatterns[i] + "/", in)) {
+ //System.out.println("["+in+"] matched ["+allowedPatterns[i]);
+ return in;
+ }
+ }
+
+ throw new UnexpectedFormatException("[" + in + "]");
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Filter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Filter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Filter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Filter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.logging.log4j.core.util;
+
+public interface Filter {
+ // 06 avr. 2002 18:36:32,036
+ // 18 fevr. 2002 20:05:36,222
+ public static final String ABSOLUTE_DATE_AND_TIME_PAT =
+ "^\\d{1,2} .{2,6}\\.? 200\\d \\d{2}:\\d{2}:\\d{2},\\d{3}";
+
+ // 18:54:19,201
+ public static final String ABSOLUTE_TIME_PAT =
+ "^\\d{2}:\\d{2}:\\d{2},\\d{3}";
+ public static final String RELATIVE_TIME_PAT = "^\\d{1,10}";
+ final String BASIC_PAT = "\\[main\\] (FATAL|ERROR|WARN|INFO|DEBUG)";
+ final String ISO8601_PAT =
+ "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3}";
+
+ /**
+ * This filter transforms the input string and returns the results as
+ * output. If the input should be ignored, this method returns null.
+ *
+ */
+ String filter(String in) throws UnexpectedFormatException;
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ISO8601Filter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ISO8601Filter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ISO8601Filter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/ISO8601Filter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+
+public class ISO8601Filter implements Filter {
+ Perl5Util util = new Perl5Util();
+
+ public String filter(String in) {
+ String pat = "/" + ISO8601_PAT + "/";
+
+ if (util.match(pat, in)) {
+ return util.substitute("s/" + ISO8601_PAT + "//", in);
+ } else {
+ return in;
+ }
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/JunitTestRunnerFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/JunitTestRunnerFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/JunitTestRunnerFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/JunitTestRunnerFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,57 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+
+public class JunitTestRunnerFilter implements Filter {
+ Perl5Util util = new Perl5Util();
+
+ private static final String[] patterns = {
+ "/at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner/",
+ "/at org.apache.tools.ant/",
+ "/at junit.textui.TestRunner/",
+ "/at com.intellij.rt.execution.junit/",
+ "/at java.lang.reflect.Method.invoke/",
+ "/at org.apache.maven.surefire./"
+ };
+
+ /**
+ * Filter out stack trace lines coming from the various JUnit TestRunners.
+ */
+ public String filter(String in) {
+ if (in == null) {
+ return null;
+ }
+
+ //
+ // restore the one instance of Method.invoke that we actually want
+ //
+ if (util.match("/at junit.framework.TestCase.runTest/", in)) {
+ return "\tat java.lang.reflect.Method.invoke(X)\n" + in;
+ }
+
+ for (int i = 0; i < patterns.length; i++) {
+ if(util.match(patterns[i], in)) {
+ return null;
+ }
+ }
+ return in;
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/LineNumberFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/LineNumberFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/LineNumberFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/LineNumberFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+
+public class LineNumberFilter implements Filter {
+ Perl5Util util = new Perl5Util();
+
+ public String filter(String in) {
+ if (util.match("/\\(.*:\\d{1,4}\\)/", in)) {
+ return util.substitute("s/\\(.*:\\d{1,4}\\)/\\(X\\)/", in);
+ } else if (util.match("/\\(Native Method\\)/", in)) {
+ return util.substitute("s/\\(Native Method\\)/\\(X\\)/", in);
+ } else {
+ return in;
+ }
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/MDCOrderFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/MDCOrderFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/MDCOrderFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/MDCOrderFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.logging.log4j.core.util;
+
+/**
+ * This class switches MDC values into the order
+ * (unreasonably) expected by the witness files.
+ */
+public class MDCOrderFilter implements Filter {
+
+ /**
+ * Unexpected orders of keys.
+ * Note expected values are "va-one-one" and "va-one-two".
+ */
+ private static final String[] patterns =
+ new String[] {
+ "{key2,va12}{key1,va11}",
+ "{key2,value2}{key1,value1}"
+ };
+
+ /**
+ * Replacement values.
+ */
+ private static final String[] replacements =
+ new String[] {
+ "{key1,va11}{key2,va12}",
+ "{key1,value1}{key2,value2}"
+ };
+
+ /**
+ * Switch order of MDC keys when not in expected order.
+ */
+ public String filter(final String in) {
+ if (in == null) {
+ return null;
+ }
+
+ for(int i = 0; i < patterns.length; i++) {
+ int ipos = in.indexOf(patterns[i]);
+ if (ipos >= 1) {
+ return in.substring(0, ipos)
+ + replacements[i]
+ + in.substring(ipos + patterns[i].length());
+ }
+ }
+ return in;
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/RelativeTimeFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/RelativeTimeFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/RelativeTimeFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/RelativeTimeFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+
+public class RelativeTimeFilter implements Filter {
+ Perl5Util util = new Perl5Util();
+
+ public String filter(String in) {
+ String pat = "/" + Filter.RELATIVE_TIME_PAT + "/";
+
+ if (util.match(pat, in)) {
+ //System.out.println("Removing relative time from line ["+in+"]");
+ return util.substitute("s/" + Filter.RELATIVE_TIME_PAT + "//", in);
+ } else {
+ return in;
+ }
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/SunReflectFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/SunReflectFilter.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/SunReflectFilter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/SunReflectFilter.java Thu May 13 06:31:04 2010
@@ -0,0 +1,40 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import org.apache.oro.text.perl.Perl5Util;
+
+/**
+ * The sun.reflect.* lines are not present in all JDKs.
+ *
+ * @author Ceki Gulcu
+ */
+public class SunReflectFilter implements Filter {
+ Perl5Util util = new Perl5Util();
+
+ public String filter(String in) {
+ if(in == null) {
+ return null;
+ }
+ if (util.match("/at sun.reflect/", in)) {
+ return null;
+ } else {
+ return in;
+ }
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Transformer.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Transformer.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Transformer.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Transformer.java Thu May 13 06:31:04 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.logging.log4j.core.util;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintStream;
+
+public class Transformer {
+
+ public
+ static
+ void transform(String in, String out, Filter[] filters) throws FileNotFoundException,
+ IOException,
+ UnexpectedFormatException {
+
+ String line;
+ BufferedReader input = new BufferedReader(new FileReader(in));
+ PrintStream output = new PrintStream(new FileOutputStream(out, false));
+
+ try {
+ // Initialization of input and output omitted
+ while ((line = input.readLine()) != null) {
+ // apply all filters
+ for (int i = 0; i < filters.length; i++) {
+ line = filters[i].filter(line);
+ }
+ if (line != null) {
+ output.println(line);
+ }
+ }
+ } finally {
+ input.close();
+ output.close();
+ }
+ }
+
+
+
+ public
+ static
+ void transform(String in, String out, Filter filter) throws FileNotFoundException,
+ IOException,
+ UnexpectedFormatException {
+
+ String line;
+ BufferedReader input = new BufferedReader(new FileReader(in));
+ PrintStream output = new PrintStream(new FileOutputStream(out));
+
+ try {
+ // Initialization of input and output omitted
+ while((line = input.readLine()) != null) {
+ line = filter.filter(line);
+ output.println(line);
+ }
+ } finally {
+ input.close();
+ output.close();
+ }
+ }
+
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/UnexpectedFormatException.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/UnexpectedFormatException.java?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/UnexpectedFormatException.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/UnexpectedFormatException.java Thu May 13 06:31:04 2010
@@ -0,0 +1,25 @@
+/*
+ * 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.logging.log4j.core.util;
+
+public class UnexpectedFormatException extends Exception {
+
+ public UnexpectedFormatException(String msg) {
+ super(msg);
+ }
+}
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml Thu May 13 06:31:04 2010
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration packages="" debug="true" name="XMLConfigTest">
+ <filters>
+ <Threshold level="debug"/>
+ </filters>
+
+ <appenders>
+ <Console name="STDOUT">
+ <PatternLayout>
+ <pattern>%m%n</pattern>
+ </PatternLayout>
+ </Console>
+ <File name="File" fileName="target/test.log">
+ <PatternLayout>
+ <pattern>%d %p %C{1.} [%t] %m%n</pattern>
+ </PatternLayout>
+ </File>
+ </appenders>
+
+ <loggers>
+ <logger name="org.apache.logging.log4j.test1" level="debug" additivity="false">
+ <filters>
+ <MDC key="test" value="123"/>
+ </filters>
+ <appender-ref ref="STDOUT"/>
+ </logger>>
+
+ <logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
+ <appender-ref ref="File"/>
+ </logger>>
+
+ <root level="error">
+ <appender-ref ref="STDOUT"/>
+ </root>
+ </loggers>
+
+</configuration>
\ No newline at end of file
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/witness/PatternParser_mdc
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/witness/PatternParser_mdc?rev=943816&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/witness/PatternParser_mdc (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/witness/PatternParser_mdc Thu May 13 06:31:04 2010
@@ -0,0 +1,12 @@
+starting mdc pattern test
+empty mdc, no key specified in pattern : {}
+empty mdc, key1 in pattern :
+empty mdc, key2 in pattern :
+empty mdc, key3 in pattern :
+empty mdc, key1, key2, and key3 in pattern : ,,
+filled mdc, no key specified in pattern : {key1=value1, key2=value2}
+filled mdc, key1 in pattern : value1
+filled mdc, key2 in pattern : value2
+filled mdc, key3 in pattern :
+filled mdc, key1, key2, and key3 in pattern : value1,value2,
+finished mdc pattern test
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org