logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1563271 - in /logging/log4j/log4j2/trunk/log4j-core/src: main/java/org/apache/logging/log4j/core/appender/ test/java/org/apache/logging/log4j/core/appender/rolling/ test/java/org/apache/logging/log4j/test/appender/
Date Fri, 31 Jan 2014 21:50:44 GMT
Author: ggregory
Date: Fri Jan 31 21:50:43 2014
New Revision: 1563271

URL: http://svn.apache.org/r1563271
Log:
Use generics on AbstractOutputStreamAppender to define what kind of OutputStreamManager is
being managed.

Added:
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
  (with props)
Modified:
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
    logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/InMemoryAppender.java

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AbstractOutputStreamAppender.java
Fri Jan 31 21:50:43 2014
@@ -27,8 +27,10 @@ import org.apache.logging.log4j.core.Log
 
 /**
  * Appends log events as bytes to a byte output stream. The stream encoding is defined in
the layout.
+ * 
+ * @param <M> The kind of {@link OutputStreamManager} under management
  */
-public abstract class AbstractOutputStreamAppender extends AbstractAppender {
+public abstract class AbstractOutputStreamAppender<M extends OutputStreamManager> extends
AbstractAppender {
 
     /**
      * Immediate flush means that the underlying writer or output stream
@@ -41,7 +43,7 @@ public abstract class AbstractOutputStre
      */
     protected final boolean immediateFlush;
 
-    private volatile OutputStreamManager manager;
+    private volatile M manager;
 
     private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
     private final Lock readLock = rwLock.readLock();
@@ -57,21 +59,26 @@ public abstract class AbstractOutputStre
      */
     protected AbstractOutputStreamAppender(final String name, final Layout<? extends Serializable>
layout, final Filter filter,
                                            final boolean ignoreExceptions, final boolean
immediateFlush,
-                                           final OutputStreamManager manager) {
+                                           final M manager) {
         super(name, filter, layout, ignoreExceptions);
         this.manager = manager;
         this.immediateFlush = immediateFlush;
     }
 
-    protected OutputStreamManager getManager() {
+    /**
+     * Gets the manager.
+     * 
+     * @return the manager.
+     */
+    public M getManager() {
         return manager;
     }
 
-    protected void replaceManager(final OutputStreamManager newManager) {
+    protected void replaceManager(final M newManager) {
 
         writeLock.lock();
         try {
-            final OutputStreamManager old = manager;
+            final M old = manager;
             manager = newManager;
             old.release();
         } finally {

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
Fri Jan 31 21:50:43 2014
@@ -46,7 +46,7 @@ import org.apache.logging.log4j.util.Pro
  * default. OTOH, a Writer cannot print byte streams.
  */
 @Plugin(name = "Console", category = "Core", elementType = "appender", printObject = true)
-public final class ConsoleAppender extends AbstractOutputStreamAppender {
+public final class ConsoleAppender extends AbstractOutputStreamAppender<OutputStreamManager>
{
 
     private static final String JANSI_CLASS = "org.fusesource.jansi.WindowsAnsiOutputStream";
     private static ConsoleManagerFactory factory = new ConsoleManagerFactory();

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java
Fri Jan 31 21:50:43 2014
@@ -37,7 +37,7 @@ import org.apache.logging.log4j.core.net
  * File Appender.
  */
 @Plugin(name = "File", category = "Core", elementType = "appender", printObject = true)
-public final class FileAppender extends AbstractOutputStreamAppender {
+public final class FileAppender extends AbstractOutputStreamAppender<FileManager> {
 
     private static final int DEFAULT_BUFFER_SIZE = 8192;
     private final String fileName;

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppender.java
Fri Jan 31 21:50:43 2014
@@ -38,7 +38,7 @@ import org.apache.logging.log4j.core.net
  * File Appender.
  */
 @Plugin(name = "RandomAccessFile", category = "Core", elementType = "appender", printObject
= true)
-public final class RandomAccessFileAppender extends AbstractOutputStreamAppender {
+public final class RandomAccessFileAppender extends AbstractOutputStreamAppender<RandomAccessFileManager>
{
 
     private final String fileName;
     private Object advertisement;

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingFileAppender.java
Fri Jan 31 21:50:43 2014
@@ -42,7 +42,7 @@ import org.apache.logging.log4j.core.net
  * An appender that writes to files and can roll over at intervals.
  */
 @Plugin(name = "RollingFile", category = "Core", elementType = "appender", printObject =
true)
-public final class RollingFileAppender extends AbstractOutputStreamAppender {
+public final class RollingFileAppender extends AbstractOutputStreamAppender<RollingFileManager>
{
 
     private final String fileName;
     private final String filePattern;

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/RollingRandomAccessFileAppender.java
Fri Jan 31 21:50:43 2014
@@ -44,7 +44,7 @@ import org.apache.logging.log4j.core.net
  * intervals.
  */
 @Plugin(name = "RollingRandomAccessFile", category = "Core", elementType = "appender", printObject
= true)
-public final class RollingRandomAccessFileAppender extends AbstractOutputStreamAppender {
+public final class RollingRandomAccessFileAppender extends AbstractOutputStreamAppender<RollingFileManager>
{
 
     private final String fileName;
     private final String filePattern;

Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/SocketAppender.java
Fri Jan 31 21:50:43 2014
@@ -41,7 +41,7 @@ import org.apache.logging.log4j.util.Eng
  * An Appender that delivers events over socket connections. Supports both TCP and UDP.
  */
 @Plugin(name = "Socket", category = "Core", elementType = "appender", printObject = true)
-public class SocketAppender extends AbstractOutputStreamAppender {
+public class SocketAppender extends AbstractOutputStreamAppender<AbstractSocketManager>
{
     private Object advertisement;
     private final Advertiser advertiser;
 

Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java?rev=1563271&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
Fri Jan 31 21:50:43 2014
@@ -0,0 +1,34 @@
+package org.apache.logging.log4j.core.appender.rolling;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.RollingFileAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.junit.Test;
+
+public class RollingFileAppenderAccessTest {
+
+    /**
+     * Not a real test, just make sure we can compile access to the typed manager.
+     * 
+     * @throws IOException
+     */
+    @Test
+    public void testAccessManager() throws IOException {
+        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
+        final Configuration config = ctx.getConfiguration();
+        final File file = File.createTempFile("RollingFileAppenderAccessTest", ".tmp");
+        file.deleteOnExit();
+        final RollingFileAppender appender = RollingFileAppender.createAppender(file.getCanonicalPath(),
"FilePattern",
+                null, "Name", null, null, OnStartupTriggeringPolicy.createPolicy(), null,
null, null, null, null, null,
+                config);
+        final RollingFileManager manager = appender.getManager();
+        // Since the RolloverStrategy and TriggeringPolicy are immutable, we could also use
generics to type their
+        // access.
+        manager.getRolloverStrategy();
+        manager.getTriggeringPolicy();
+    }
+}

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingFileAppenderAccessTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/InMemoryAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/InMemoryAppender.java?rev=1563271&r1=1563270&r2=1563271&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/InMemoryAppender.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/InMemoryAppender.java
Fri Jan 31 21:50:43 2014
@@ -27,7 +27,7 @@ import org.apache.logging.log4j.core.fil
 /**
  *
  */
-public class InMemoryAppender extends AbstractOutputStreamAppender {
+public class InMemoryAppender extends AbstractOutputStreamAppender<InMemoryAppender.InMemoryManager>
{
 
     public InMemoryAppender(final String name, final Layout<? extends Serializable>
layout, final CompositeFilter filters,
                             final boolean ignoreExceptions) {
@@ -39,7 +39,7 @@ public class InMemoryAppender extends Ab
         return getManager().toString();
     }
 
-    private static class InMemoryManager extends OutputStreamManager {
+    static class InMemoryManager extends OutputStreamManager {
 
         public InMemoryManager(final String name, final Layout<? extends Serializable>
layout) {
             super(new ByteArrayOutputStream(), name, layout);



Mime
View raw message