Author: carnold
Date: Tue Oct 10 20:12:24 2006
New Revision: 462679
URL: http://svn.apache.org/viewvc?view=rev&rev=462679
Log:
Initial commit
Added:
logging/sandbox/log4j/multifile/
logging/sandbox/log4j/multifile/LICENSE
logging/sandbox/log4j/multifile/NOTICE
logging/sandbox/log4j/multifile/pom.xml
logging/sandbox/log4j/multifile/src/
logging/sandbox/log4j/multifile/src/main/
logging/sandbox/log4j/multifile/src/main/java/
logging/sandbox/log4j/multifile/src/main/java/org/
logging/sandbox/log4j/multifile/src/main/java/org/apache/
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/FileNamePolicy.java
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/MultiFileAppenderListener.java
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/PatternFileNamePolicy.java
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/SizeBasedFileNamePolicy.java
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/package.html
logging/sandbox/log4j/multifile/src/test/
logging/sandbox/log4j/multifile/src/test/java/
logging/sandbox/log4j/multifile/src/test/java/org/
logging/sandbox/log4j/multifile/src/test/java/org/apache/
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/PatternFileNamePolicyTest.java
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/SizeBasedFileNamePolicyTest.java
Added: logging/sandbox/log4j/multifile/LICENSE
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/LICENSE?view=auto&rev=462679
==============================================================================
--- logging/sandbox/log4j/multifile/LICENSE (added)
+++ logging/sandbox/log4j/multifile/LICENSE Tue Oct 10 20:12:24 2006
@@ -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 [yyyy] [name of copyright owner]
+
+ 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/sandbox/log4j/multifile/NOTICE
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/NOTICE?view=auto&rev=462679
==============================================================================
--- logging/sandbox/log4j/multifile/NOTICE (added)
+++ logging/sandbox/log4j/multifile/NOTICE Tue Oct 10 20:12:24 2006
@@ -0,0 +1,2 @@
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
Added: logging/sandbox/log4j/multifile/pom.xml
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/pom.xml?view=auto&rev=462679
==============================================================================
--- logging/sandbox/log4j/multifile/pom.xml (added)
+++ logging/sandbox/log4j/multifile/pom.xml Tue Oct 10 20:12:24 2006
@@ -0,0 +1,115 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.log4j.multifile</groupId>
+ <artifactId>apache-log4j-multifile</artifactId>
+ <packaging>jar</packaging>
+ <version>0.1</version>
+ <name>Multifile appenders for log4j</name>
+ <description>This project provides log4j appenders that can append to
multiple files. Potential applications include segregating messages by thread
id, by arbitrary MDC value or by date.</description>
+ <url>http://logging.apache.org/log4j</url>
+ <issueManagement>
+ <system>Bugzilla</system>
+ <url>http://issues.apache.org/bugzilla</url>
+ </issueManagement>
+ <inceptionYear>2006</inceptionYear>
+<mailingLists>
+ <mailingList>
+ <name>log4j-user</name>
+ <subscribe>[EMAIL PROTECTED]</subscribe>
+ <unsubscribe>[EMAIL PROTECTED]</unsubscribe>
+ <post>[email protected]</post>
+
<archive>http://mail-archives.apache.org/mod_mbox/logging-log4j-dev/</archive>
+ <otherArchives>
+
<otherArchive>http://marc.theaimsgroup.com/?l=log4j-user&r=1&w=2</otherArchive>
+
<otherArchive>http://dir.gmane.org/gmane.comp.jakarta.log4j.user</otherArchive>
+ </otherArchives>
+ </mailingList>
+ <mailingList>
+ <name>log4j-dev</name>
+ <subscribe>[EMAIL PROTECTED]</subscribe>
+ <unsubscribe>[EMAIL PROTECTED]</unsubscribe>
+ <post>[email protected]</post>
+
<archive>http://mail-archives.apache.org/mod_mbox/logging-log4j-dev/</archive>
+ <otherArchives>
+
<otherArchive>http://marc.theaimsgroup.com/?l=log4j-dev&r=1&w=2</otherArchive>
+
<otherArchive>http://dir.gmane.org/gmane.comp.jakarta.log4j.devel</otherArchive>
+ </otherArchives>
+ </mailingList>
+</mailingLists>
+<developers>
+ <developer>
+ <id>carnold</id>
+ <name>Curt Arnold</name>
+ <email>[EMAIL PROTECTED]</email>
+ </developer>
+</developers>
+<licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+ <distribution>repo</distribution>
+ </license>
+</licenses>
+<scm>
+
<connection>scm:svn:http://svn.apache.org/repos/asf/logging/sandbox/log4j/multifile</connection>
+
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/logging/sandbox/log4j/multifile</developerConnection>
+
<url>http://svn.apache.org/viewcvs.cgi/logging/sandbox/log4j/multifile</url>
+</scm>
+<organization>
+ <name>Apache Software Foundation</name>
+ <url>http://www.apache.org</url>
+</organization>
+<build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.12</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+</build>
+<reporting>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-pmd-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ </plugin>
+ <!-- plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ </plugin-->
+ <!-- plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>jxr-maven-plugin</artifactId>
+ </plugin -->
+ <!-- plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>changelog-maven-plugin</artifactId>
+ </plugin -->
+ </plugins>
+ </reporting>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.12</version>
+ </dependency>
+ </dependencies>
+</project>
Added:
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/FileNamePolicy.java
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/FileNamePolicy.java?view=auto&rev=462679
==============================================================================
---
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/FileNamePolicy.java
(added)
+++
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/FileNamePolicy.java
Tue Oct 10 20:12:24 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.log4j.multifile;
+import org.apache.log4j.spi.LoggingEvent;
+
+/**
+ * The interface used to determine the desired file name
+ * for the specified logging event.
+ *
+ * @author Curt Arnold
+ */
+public interface FileNamePolicy {
+ /**
+ * Get the desired file name for the specified logging event.
+ * @param event event, may not be null.
+ * @return desired file name, may be null in which case
+ * default file name will be used.
+ */
+ String getFileName(final LoggingEvent event);
+}
Added:
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/MultiFileAppenderListener.java
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/MultiFileAppenderListener.java?view=auto&rev=462679
==============================================================================
---
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/MultiFileAppenderListener.java
(added)
+++
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/MultiFileAppenderListener.java
Tue Oct 10 20:12:24 2006
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.log4j.multifile;
+
+/**
+ * The interface implemented by objects that monitor MultiFileAppender.
+ *
+ * @author Curt Arnold
+ */
+public interface MultiFileAppenderListener {
+ /**
+ * This tells that the new size of the file after the append operation.
+ *
+ * @param fileName file name, may not be null.
+ * @param fileSize file size after append.
+ */
+ void fileAppended(final String fileName, final long fileSize);
+}
Added:
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/PatternFileNamePolicy.java
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/PatternFileNamePolicy.java?view=auto&rev=462679
==============================================================================
---
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/PatternFileNamePolicy.java
(added)
+++
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/PatternFileNamePolicy.java
Tue Oct 10 20:12:24 2006
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.log4j.multifile;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.OptionHandler;
+import org.apache.log4j.PatternLayout;
+
+/**
+ * FileNamePolicy that delegates to a PatternLayout to generate file name.
+ *
+ * @author Curt Arnold
+ */
+public final class PatternFileNamePolicy
+ implements FileNamePolicy, OptionHandler {
+ /**
+ * Conversion pattern.
+ */
+ private String conversionPattern;
+ /**
+ * Layout.
+ */
+ private PatternLayout layout;
+ /**
+ * Creates an instance of PatternFileNamePolicy.
+ */
+ public PatternFileNamePolicy() {
+ }
+ /**
+ * Get the desired file name for the specified logging event.
+ * @param event event, may not be null.
+ * @return desired file name, may be null in which case
+ * default file name will be used.
+ */
+ public synchronized String getFileName(final LoggingEvent event) {
+ if (layout == null) {
+ return null;
+ }
+ return layout.format(event);
+ }
+
+ /**
+ * This tells that configuration is complete and
+ * policy should be made ready for use.
+ */
+ public synchronized void activateOptions() {
+ if (conversionPattern == null) {
+ layout = null;
+ } else {
+ layout = new PatternLayout(conversionPattern);
+ }
+ }
+
+ /**
+ * Set pattern.
+ * New pattern will not be effective until activateOptions is called.
+ * @param pattern new pattern, may be null.
+ */
+ public synchronized void setConversionPattern(final String pattern) {
+ conversionPattern = pattern;
+ }
+
+ /**
+ * Get pattern.
+ * @return pattern, may be null.
+ */
+ public synchronized String getConversionPattern() {
+ return conversionPattern;
+ }
+}
Added:
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/SizeBasedFileNamePolicy.java
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/SizeBasedFileNamePolicy.java?view=auto&rev=462679
==============================================================================
---
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/SizeBasedFileNamePolicy.java
(added)
+++
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/SizeBasedFileNamePolicy.java
Tue Oct 10 20:12:24 2006
@@ -0,0 +1,231 @@
+/*
+ * Copyright 2006 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.
+ */
+package org.apache.log4j.multifile;
+
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.OptionHandler;
+import org.apache.log4j.helpers.OptionConverter;
+
+import java.io.File;
+
+/**
+ * File name policy that increments an integer suffix when
+ * the file size exceeds a specified threshold.
+ *
+ * @author Curt Arnold
+ */
+public final class SizeBasedFileNamePolicy
+ implements FileNamePolicy, MultiFileAppenderListener, OptionHandler {
+ /**
+ * Base file name.
+ */
+ private String baseFilename;
+
+ /**
+ * Current file name, includes file index.
+ */
+ private String currentFilename;
+
+ /**
+ * Current file index.
+ */
+ private int currentIndex;
+
+ /**
+ * Default value for maxFileSize.
+ */
+ private static final long DEFAULT_MAX_SIZE = 10485760;
+
+ /**
+ *The default maximum file size is 10MB.
+ */
+ private long maxFileSize = DEFAULT_MAX_SIZE;
+
+
+ /**
+ * Creates an instance of SizeFileNamePolicy.
+ */
+ public SizeBasedFileNamePolicy() {
+ }
+ /**
+ * Get the desired file name for the specified logging event.
+ * @param event event, may not be null.
+ * @return desired file name, may be null in which case
+ * default file name will be used.
+ */
+ public synchronized String getFileName(final LoggingEvent event) {
+ return currentFilename;
+ }
+
+ /**
+ * This filter examines the files passed to it for consideration
+ * and extracts the maximum file index from the suffix.
+ */
+ private static final class SizeBasedFilenameFilter
+ implements java.io.FilenameFilter {
+ /**
+ * Base file name including period.
+ */
+ private final String baseName;
+ /**
+ * Maximum index encountered.
+ */
+ private int maxIndex;
+
+ /**
+ * Creates new instance.
+ * @param name base file name.
+ */
+ public SizeBasedFilenameFilter(final String name) {
+ maxIndex = Integer.MIN_VALUE;
+ this.baseName = name + ".";
+ }
+
+ /**
+ * Determines if the file should be included in the result set.
+ * @param dir directory containing file.
+ * @param name file name.
+ * @return true if file should be included in result set.
+ */
+ public boolean accept(final File dir, final String name) {
+ if (name.length() > baseName.length()
+ && name.startsWith(baseName)) {
+ try {
+ int index = Integer.parseInt(
+ name.substring(baseName.length()));
+ if (index > maxIndex) {
+ maxIndex = index;
+ }
+ } catch (NumberFormatException ex) {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get maximum index encountered.
+ * @return maximum index encountered, Integer.MIN_VALUE if no matches.
+ */
+ public int getMaxIndex() {
+ return maxIndex;
+ }
+ }
+
+ /**
+ * Update file name based on current file size.
+ * @param fileSize file size.
+ */
+ private void updateFilename(final long fileSize) {
+ if (fileSize > maxFileSize) {
+ currentFilename = baseFilename
+ + "." + Integer.toString(++currentIndex);
+ }
+ }
+
+ /**
+ * Set maximum file size.
+ * @param newValue maximum file size.
+ */
+ public synchronized void setMaximumFileSize(final long newValue) {
+ this.maxFileSize = newValue;
+ }
+
+ /**
+ * Get maximum file size.
+ * @return maximum file size.
+ */
+ public synchronized long getMaximumFileSize() {
+ return maxFileSize;
+ }
+
+ /**
+ * Set base file name.
+ * @param file new value.
+ */
+ public synchronized void setFile(final String file) {
+ baseFilename = file;
+ }
+
+ /**
+ * Get base file name.
+ * @return base file name.
+ */
+ public synchronized String getFile() {
+ return baseFilename;
+ }
+
+
+ /**
+ *
+ * Set the maximum file size.
+ * @param value maximum file size,
+ * suffixes "KB", "MB" and "GB" are supported.
+ *
+ */
+ public synchronized void setMaxFileSize(final String value) {
+ maxFileSize = OptionConverter.toFileSize(value, maxFileSize + 1);
+ }
+
+
+ /**
+ * This tells that configuration is complete
+ * and policy should be made ready for use.
+ */
+ public synchronized void activateOptions() {
+ currentFilename = null;
+ if (baseFilename != null) {
+ try {
+ File base = new File(baseFilename);
+ File parentDir = base.getParentFile();
+ if (parentDir == null) {
+ parentDir = new File(System.getProperty("user.dir"));
+ }
+ if (parentDir.exists()) {
+ SizeBasedFilenameFilter filter =
+ new SizeBasedFilenameFilter(base.getName());
+ parentDir.list(filter);
+ int maxIndex = filter.getMaxIndex();
+ if (maxIndex < 0) {
+ currentIndex = 0;
+ currentFilename = baseFilename + ".0";
+ } else {
+ currentIndex = maxIndex;
+ currentFilename = baseFilename
+ + "." + Integer.toString(currentIndex);
+ File currentFile = new File(currentFilename);
+ updateFilename(currentFile.length());
+ }
+ }
+ } catch (Exception ex) {
+ currentFilename = null;
+ }
+ }
+ }
+
+ /**
+ * This tells that the new size of the file after the append operation.
+ *
+ * @param fileName file name, may not be null.
+ * @param fileSize file size after append.
+ */
+ public void fileAppended(final String fileName, final long fileSize) {
+ updateFilename(fileSize);
+ }
+
+
+
+}
Added:
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/package.html
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/package.html?view=auto&rev=462679
==============================================================================
---
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/package.html
(added)
+++
logging/sandbox/log4j/multifile/src/main/java/org/apache/log4j/multifile/package.html
Tue Oct 10 20:12:24 2006
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+ Copyright 2006 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.
+
+-->
+</head>
+<body bgcolor="white">
+
+Provides appenders that write to files where the file name
+is not fixed, but determined by logging event contents.
+</body>
+</html>
Added:
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/PatternFileNamePolicyTest.java
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/PatternFileNamePolicyTest.java?view=auto&rev=462679
==============================================================================
---
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/PatternFileNamePolicyTest.java
(added)
+++
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/PatternFileNamePolicyTest.java
Tue Oct 10 20:12:24 2006
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.log4j.multifile;
+
+import junit.framework.TestCase;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+
+/**
+ * Tests of PatternFileNamePolicy.
+ */
+public final class PatternFileNamePolicyTest extends TestCase {
+ /**
+ * Logger.
+ */
+ private static final Logger logger =
+
Logger.getLogger("org.apache.log4j.multifile.PatternFileNamePolicyTest");
+ /**
+ * Create the test case.
+ *
+ * @param testName name of the test case
+ */
+ public PatternFileNamePolicyTest(final String testName ) {
+ super(testName);
+ }
+
+ /**
+ * Test default constructor.
+ */
+ public void testConstructor() {
+ PatternFileNamePolicy patternPolicy = new PatternFileNamePolicy();
+ assertTrue(patternPolicy instanceof FileNamePolicy);
+ assertNull(patternPolicy.getConversionPattern());
+ }
+
+
+ /**
+ * Test getFileName when no pattern has been specified.
+ */
+ public void testNoPattern() {
+ PatternFileNamePolicy patternPolicy = new PatternFileNamePolicy();
+ patternPolicy.activateOptions();
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = patternPolicy.getFileName(event);
+ assertNull(fileName);
+ }
+
+ /**
+ * Test get and set pattern.
+ */
+ public void testGetSetPattern() {
+ PatternFileNamePolicy patternPolicy = new PatternFileNamePolicy();
+ final String pattern = "%t.log";
+ patternPolicy.setConversionPattern(pattern);
+ assertEquals(pattern, patternPolicy.getConversionPattern());
+ }
+
+ /**
+ * Test getFileName when pattern has been specified, but activateOptions
was not called.
+ */
+ public void testPatternNoActivate() {
+ PatternFileNamePolicy patternPolicy = new PatternFileNamePolicy();
+ patternPolicy.setConversionPattern("%t.log");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = patternPolicy.getFileName(event);
+ assertNull(fileName);
+ }
+
+ /**
+ * Test getFileName when with pattern containing thread name.
+ */
+ public void testThreadPattern() {
+ PatternFileNamePolicy patternPolicy = new PatternFileNamePolicy();
+ patternPolicy.setConversionPattern("/tmp/%t.log");
+ patternPolicy.activateOptions();
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = patternPolicy.getFileName(event);
+ assertEquals("/tmp/" + Thread.currentThread().getName() + ".log",
fileName);
+ }
+}
Added:
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/SizeBasedFileNamePolicyTest.java
URL:
http://svn.apache.org/viewvc/logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/SizeBasedFileNamePolicyTest.java?view=auto&rev=462679
==============================================================================
---
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/SizeBasedFileNamePolicyTest.java
(added)
+++
logging/sandbox/log4j/multifile/src/test/java/org/apache/log4j/multifile/SizeBasedFileNamePolicyTest.java
Tue Oct 10 20:12:24 2006
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2006 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.
+ */
+
+package org.apache.log4j.multifile;
+
+import junit.framework.TestCase;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Level;
+import java.io.File;
+import java.io.IOException;
+import java.io.*;
+
+/**
+ * Tests of SizeBasedFileNamePolicy.
+ */
+public final class SizeBasedFileNamePolicyTest extends TestCase {
+ /**
+ * Logger.
+ */
+ private static final Logger logger =
+
Logger.getLogger("org.apache.log4j.multifile.SizeBasedFileNamePolicyTest");
+ /**
+ * Create the test case.
+ *
+ * @param testName name of the test case
+ */
+ public SizeBasedFileNamePolicyTest(final String testName ) {
+ super(testName);
+ }
+
+ /**
+ * Test default constructor.
+ */
+ public void testConstructor() {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ assertEquals(10 * 1024 * 1024, policy.getMaximumFileSize());
+ assertNull(policy.getFile());
+ }
+
+
+ /**
+ * Test getFileName when no base file has been specified.
+ */
+ public void testNoBase() {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ policy.activateOptions();
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = policy.getFileName(event);
+ assertNull(fileName);
+ }
+
+ /**
+ * Test get and set pattern.
+ */
+ public void tesSetMaxFileSize() {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ policy.setMaxFileSize("1MB");
+ assertEquals(1 * 1024 * 1024, policy.getMaximumFileSize());
+ }
+
+ /**
+ * Test getFileName when pattern has been specified, but activateOptions
was not called.
+ */
+ public void testBaseNoActivate() {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ policy.setFile("foobar");
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = policy.getFileName(event);
+ assertNull(fileName);
+ }
+
+ /**
+ *
+ * Tests getFileName when there is no existing file that matches the
pattern.
+ *
+ */
+ public void testNoExistingFiles() {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ String baseFile = System.getProperty("java.io.tmpdir") +
"/testNoExistingFiles.log";
+ // should not exist, but delete it anyway.
+ new File(baseFile).delete();
+ policy.setFile(baseFile);
+ policy.activateOptions();
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = policy.getFileName(event);
+ assertEquals(baseFile + ".0", fileName);
+ }
+
+ /**
+ * Tests getFileName when the directory does not exist.
+ *
+ */
+ public void testBadDirectory() {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ String baseFile = System.getProperty("java.io.tmpdir") +
"/testBadDirectory/foobar.log";
+ policy.setFile(baseFile);
+ policy.activateOptions();
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = policy.getFileName(event);
+ assertNull(fileName);
+ }
+
+ /**
+ * Tests getFileName when existing log file is present.
+ *
+ */
+ public void testExistingFile() throws IOException {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ String baseFile = System.getProperty("java.io.tmpdir")
+ + "/SizeBasedFileNamePolicyTest_testExistingFile";
+ File file1 = new File(baseFile + ".17");
+ file1.createNewFile();
+ File file2 = new File(baseFile + ".two");
+ file2.createNewFile();
+ policy.setFile(baseFile);
+ policy.activateOptions();
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = policy.getFileName(event);
+ assertEquals(baseFile + ".17", fileName);
+ file1.delete();
+ file2.delete();
+ }
+
+
+ /**
+ * Tests getFileName when existing log file is present already exceeds
limit.
+ *
+ */
+ public void testExistingFullFile() throws IOException {
+ SizeBasedFileNamePolicy policy = new SizeBasedFileNamePolicy();
+ String baseFile = System.getProperty("java.io.tmpdir")
+ + "/SizeBasedFileNamePolicyTest_testExistingFullFile";
+ Writer writer = new FileWriter(baseFile + ".0");
+ writer.write("INFO Hello, World\n");
+ writer.close();
+ policy.setFile(baseFile);
+ policy.setMaximumFileSize(10);
+ policy.activateOptions();
+ LoggingEvent event = new LoggingEvent("org.apache.log4j.Logger",
logger,
+ Level.INFO, "Hello, World", null);
+ String fileName = policy.getFileName(event);
+ assertEquals(baseFile + ".1", fileName);
+ new File(baseFile + ".0").delete();
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]