You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Narendra Babu Kirthi <nk...@cisco.com> on 2004/08/26 17:36:09 UTC

log4j:ERROR Attempted to append to closed appender named error

Hi,

    This mail is regarding configuring some properties in log4j.
    If any one has come across such situation, please throw some info here.
    Please bear with me for writing such a long mail.
   
Issue :
   
    When we have a category set for a package in different properties files,
    the appenders set for the first are closed when log4j loads the 
second properties file.

    Let me explain in detail ...
   
    Say I have a category set in logOne.properties, say
       log4j.category.testThree.Log4jTestThree=INFO,fileLog
    Also the same is set in another properties file Say 
logTwo.properties, i.e
       log4j.category.testThree.Log4jTestThree=INFO,fileLogTwo.

    In my source program One.
    Program {
       ...
       I load logOne.properties
       ....
       Call to the another program where the logTwo.properties is loaded.
          {
                In Second program
                ....
                Call to the third program ....
                   {
                       ...here it does not load any log4j properties file,
                       ...it just gets category object and logs message.
                       ...for logging it uses the appenders that are set 
in the
                       ...(logOne.properties or) logTwo.properties file.
                   }
            }
       ...
       ...
    }
   
    What log4j does at loading the second property file is, It closes 
the appenders that
    are set before for testThree.Log4jTestThree.
    i.e it closes the appender fileLog and sets the appender to fileLogTwo.

    I have written the same, what I have explained above in test programs .
    Hope that will easier, if any one debugs. I have attached the 
programs with this mail.
    If some one finds a way out of this , please let me know.

    Here is the debug info, I got on running the program.
-------------------------------------------------------
log4j: Could not find root category information. Is this OK?
log4j: Parsing for [testThree.Log4jTestThree] with value=[INFO,fileLog].
log4j: Priority token is [INFO].
log4j: Category testThree.Log4jTestThree set to INFO
log4j: Parsing appender named "fileLog".
log4j: Parsing layout options for "fileLog".
log4j: Setting property [conversionPattern] to [%m %p %r %c %t %x %% %d 
%l %C %M %F %L %n].
log4j: End of parsing for "fileLog".
log4j: Setting property [file] to [TestLogOne.log].
log4j: Parsed "fileLog" options.
log4j: Handling log4j.additivity.testThree.Log4jTestThree=[null]
log4j: Parsing for [testOne] with value=[DEBUG,fileLog].
log4j: Priority token is [DEBUG].
log4j: Category testOne set to DEBUG
log4j: Parsing appender named "fileLog".
log4j: Appender "fileLog" was already parsed.
log4j: Handling log4j.additivity.testOne=[null]
log4j: Finished configuring.
In test three.
End test three.
log4j: Could not find root category information. Is this OK?
log4j: Parsing for [testThree.Log4jTestThree] with value=[INFO,fileLogTwo].
log4j: Priority token is [INFO].
log4j: Category testThree.Log4jTestThree set to INFO
log4j: Parsing appender named "fileLogTwo".
log4j: Parsing layout options for "fileLogTwo".
log4j: Setting property [conversionPattern] to [%m %p %r %c %t %x %% %d 
%l %C %M %F %L %n].
log4j: End of parsing for "fileLogTwo".
log4j: Setting property [file] to [TestLogTwo.log].
log4j: Parsed "fileLogTwo" options.
log4j: Handling log4j.additivity.testThree.Log4jTestThree=[null]
log4j: Parsing for [testTwo] with value=[DEBUG,fileLogTwo].
log4j: Priority token is [DEBUG].
log4j: Category testTwo set to DEBUG
log4j: Parsing appender named "fileLogTwo".
log4j: Appender "fileLogTwo" was already parsed.
log4j: Handling log4j.additivity.testTwo=[null]
log4j: Finished configuring.
In other package
Calling third package
In test three.
End test three.
log4j:ERROR Attempted to append to closed appender named [fileLog].
log4j:WARN Not allowed to write to a closed appender.
-------------------------------------------------------

All the above is with respect to log4j 1.1.3 version.


logPropTwo.properties
-----------------------
#log4j.rootCategory=,fileLogTwo
log4j.category.testTwo=DEBUG,fileLogTwo
log4j.category.testThree.Log4jTestThree=INFO,fileLogTwo
log4j.fileLog.testThree.Log4jTestThree.Threshold=DEBUG
log4j.appender.fileLogTwo=org.apache.log4j.FileAppender
log4j.appender.fileLogTwo.File=TestLogTwo.log
log4j.appender.fileLogTwo.layout=org.apache.log4j.PatternLayout
log4j.appender.fileLogTwo.layout.ConversionPattern=%m %p %r %c %t %x %% %d %l %C %M %F %L %n


Log4jTestThree.java
--------------------
package testThree;
import org.apache.log4j.*;
import org.apache.log4j.spi.*;
import java.io.*;
import util.*;

public class Log4jTestThree
{
//	private static final Category cat = Category.getInstance(testOne.Log4jTest.class);
	private static final Category cat = Category.getInstance(testThree.Log4jTestThree.class);
	public static void test() 
	{
//			System.out.println("Hi :"+new PatternLayout().getConversionPattern());
//			System.out.println("Hello 1:"+new MyPatternParser("%M").parse());
//			System.out.println("Hellow 2:"+new LocationInfo(new Throwable(),"testOne.Log4jTest.class").fullInfo);
//			new MyPatternParser("%M").finalizeConverter('M');

			System.out.println("In test three.");
			cat.info("Hello Three");
			System.out.println("End test three.");

	}
	
}


Log4jTestTwo.java
----------------------
package testTwo;
import org.apache.log4j.*;
import java.io.*;

public class Log4jTestTwo 
{
	private static Category  cat1;
	static
	{
			PropertyConfigurator.configure("logPropTwo.properties");
			cat1 = Category.getInstance(testTwo.Log4jTestTwo.class);
	}

	public static void test()
	{
			System.out.println("In other package");
			cat1.info("Hello TWO");
			System.out.println("Calling third package");
			testThree.Log4jTestThree.test();
	}
}

logPropOne.properties
------------------------
log4j.debug=true
#lo4j.rootCategory=,fileLog
log4j.category.testOne=DEBUG,fileLog
log4j.category.testThree.Log4jTestThree=INFO,fileLog
log4j.fileLog.testThree.Log4jTestThree.Threshold=DEBUG

log4j.appender.fileLog=org.apache.log4j.FileAppender
log4j.appender.fileLog.File=TestLogOne.log
log4j.appender.fileLog.layout=org.apache.log4j.PatternLayout
log4j.appender.fileLog.layout.ConversionPattern=%m %p %r %c %t %x %% %d %l %C %M %F %L %n

Log4jTest.java
------------------------
package testOne;
import org.apache.log4j.*;
import testTwo.*;
import java.io.*;

public class Log4jTest 
{
	static {
		PropertyConfigurator.configure("logPropOne.properties");
	}

	private static final Category cat = Category.getInstance(testOne.Log4jTest.class);
	
	Log4jTest() 
	{
		try
		{
			cat.info("Hello ONE");
			//System.out.println("Calling three from One");
			testThree.Log4jTestThree.test();
			//System.out.println("End calling three from One");
			//System.out.println("Going to other package");
			testTwo.Log4jTestTwo.test();
			//System.out.println("Came out from other package");
			cat.info("Hello ONE:ONE");

		}
		catch (Exception e)
		{
			System.out.println("Except :"+e);
		}
	}
	public static void main(String[] args) throws IOException
	{
		new Log4jTest();
	}
}

Regards
Naren


Re: log4j:ERROR Attempted to append to closed appender named error

Posted by Narendra Babu Kirthi <nk...@cisco.com>.
Hi,
    Let me explain the problem in simple,
    I have two log4j.properties (1 & 2).
    I have a category set in 1. properties, say 
log4j.category.com.Three=INFO,A1
    I have also set the same category in 2.properties, i.e 
log4j.category.Three=INFO,A2
    I have three java programs say One.java, Two.java, Three.java.
    Say One.java loads 1. properties and Two.java loads 2.properties.
    My intention is If One.java calls Three.java, then all the messages 
from Three.java should go to One's appender.
    If Two.java calls Three.java, then all the messages from Three.java 
should go to Two's appender.
    But when I set the properties as said, then I am getting this 
log4j:ERROR attepted to append to closed appender named error.
    The problem is when One calls Two and Two calls Three, It works fine 
till Two, i.e Threes's messages are gone to Two's appender,
    and when the call comes back again to One, then the appenders are 
getting closed, as when Two.java loads the 2. properties it is
    closing the appenders set to Three by 1.properties.
    Is there any way out to this problem ?
    Please let me know.

Regards
Naren

Narendra Babu Kirthi wrote:

>
> Hi,
>
>    This mail is regarding configuring some properties in log4j.
>    If any one has come across such situation, please throw some info 
> here.
>    Please bear with me for writing such a long mail.
>   Issue :
>      When we have a category set for a package in different properties 
> files,
>    the appenders set for the first are closed when log4j loads the 
> second properties file.
>
>    Let me explain in detail ...
>      Say I have a category set in logOne.properties, say
>       log4j.category.testThree.Log4jTestThree=INFO,fileLog
>    Also the same is set in another properties file Say 
> logTwo.properties, i.e
>       log4j.category.testThree.Log4jTestThree=INFO,fileLogTwo.
>
>    In my source program One.
>    Program {
>       ...
>       I load logOne.properties
>       ....
>       Call to the another program where the logTwo.properties is loaded.
>          {
>                In Second program
>                ....
>                Call to the third program ....
>                   {
>                       ...here it does not load any log4j properties file,
>                       ...it just gets category object and logs message.
>                       ...for logging it uses the appenders that are 
> set in the
>                       ...(logOne.properties or) logTwo.properties file.
>                   }
>            }
>       ...
>       ...
>    }
>      What log4j does at loading the second property file is, It closes 
> the appenders that
>    are set before for testThree.Log4jTestThree.
>    i.e it closes the appender fileLog and sets the appender to 
> fileLogTwo.
>
>    I have written the same, what I have explained above in test 
> programs .
>    Hope that will easier, if any one debugs. I have attached the 
> programs with this mail.
>    If some one finds a way out of this , please let me know.
>
>    Here is the debug info, I got on running the program.
> -------------------------------------------------------
> log4j: Could not find root category information. Is this OK?
> log4j: Parsing for [testThree.Log4jTestThree] with value=[INFO,fileLog].
> log4j: Priority token is [INFO].
> log4j: Category testThree.Log4jTestThree set to INFO
> log4j: Parsing appender named "fileLog".
> log4j: Parsing layout options for "fileLog".
> log4j: Setting property [conversionPattern] to [%m %p %r %c %t %x %% 
> %d %l %C %M %F %L %n].
> log4j: End of parsing for "fileLog".
> log4j: Setting property [file] to [TestLogOne.log].
> log4j: Parsed "fileLog" options.
> log4j: Handling log4j.additivity.testThree.Log4jTestThree=[null]
> log4j: Parsing for [testOne] with value=[DEBUG,fileLog].
> log4j: Priority token is [DEBUG].
> log4j: Category testOne set to DEBUG
> log4j: Parsing appender named "fileLog".
> log4j: Appender "fileLog" was already parsed.
> log4j: Handling log4j.additivity.testOne=[null]
> log4j: Finished configuring.
> In test three.
> End test three.
> log4j: Could not find root category information. Is this OK?
> log4j: Parsing for [testThree.Log4jTestThree] with 
> value=[INFO,fileLogTwo].
> log4j: Priority token is [INFO].
> log4j: Category testThree.Log4jTestThree set to INFO
> log4j: Parsing appender named "fileLogTwo".
> log4j: Parsing layout options for "fileLogTwo".
> log4j: Setting property [conversionPattern] to [%m %p %r %c %t %x %% 
> %d %l %C %M %F %L %n].
> log4j: End of parsing for "fileLogTwo".
> log4j: Setting property [file] to [TestLogTwo.log].
> log4j: Parsed "fileLogTwo" options.
> log4j: Handling log4j.additivity.testThree.Log4jTestThree=[null]
> log4j: Parsing for [testTwo] with value=[DEBUG,fileLogTwo].
> log4j: Priority token is [DEBUG].
> log4j: Category testTwo set to DEBUG
> log4j: Parsing appender named "fileLogTwo".
> log4j: Appender "fileLogTwo" was already parsed.
> log4j: Handling log4j.additivity.testTwo=[null]
> log4j: Finished configuring.
> In other package
> Calling third package
> In test three.
> End test three.
> log4j:ERROR Attempted to append to closed appender named [fileLog].
> log4j:WARN Not allowed to write to a closed appender.
> -------------------------------------------------------
>
> All the above is with respect to log4j 1.1.3 version.
>
>
> logPropTwo.properties
> -----------------------
> #log4j.rootCategory=,fileLogTwo
> log4j.category.testTwo=DEBUG,fileLogTwo
> log4j.category.testThree.Log4jTestThree=INFO,fileLogTwo
> log4j.fileLog.testThree.Log4jTestThree.Threshold=DEBUG
> log4j.appender.fileLogTwo=org.apache.log4j.FileAppender
> log4j.appender.fileLogTwo.File=TestLogTwo.log
> log4j.appender.fileLogTwo.layout=org.apache.log4j.PatternLayout
> log4j.appender.fileLogTwo.layout.ConversionPattern=%m %p %r %c %t %x 
> %% %d %l %C %M %F %L %n
>
>
> Log4jTestThree.java
> --------------------
> package testThree;
> import org.apache.log4j.*;
> import org.apache.log4j.spi.*;
> import java.io.*;
> import util.*;
>
> public class Log4jTestThree
> {
> //    private static final Category cat = 
> Category.getInstance(testOne.Log4jTest.class);
>     private static final Category cat = 
> Category.getInstance(testThree.Log4jTestThree.class);
>     public static void test()     {
> //            System.out.println("Hi :"+new 
> PatternLayout().getConversionPattern());
> //            System.out.println("Hello 1:"+new 
> MyPatternParser("%M").parse());
> //            System.out.println("Hellow 2:"+new LocationInfo(new 
> Throwable(),"testOne.Log4jTest.class").fullInfo);
> //            new MyPatternParser("%M").finalizeConverter('M');
>
>             System.out.println("In test three.");
>             cat.info("Hello Three");
>             System.out.println("End test three.");
>
>     }
>     
> }
>
>
> Log4jTestTwo.java
> ----------------------
> package testTwo;
> import org.apache.log4j.*;
> import java.io.*;
>
> public class Log4jTestTwo {
>     private static Category  cat1;
>     static
>     {
>             PropertyConfigurator.configure("logPropTwo.properties");
>             cat1 = Category.getInstance(testTwo.Log4jTestTwo.class);
>     }
>
>     public static void test()
>     {
>             System.out.println("In other package");
>             cat1.info("Hello TWO");
>             System.out.println("Calling third package");
>             testThree.Log4jTestThree.test();
>     }
> }
>
> logPropOne.properties
> ------------------------
> log4j.debug=true
> #lo4j.rootCategory=,fileLog
> log4j.category.testOne=DEBUG,fileLog
> log4j.category.testThree.Log4jTestThree=INFO,fileLog
> log4j.fileLog.testThree.Log4jTestThree.Threshold=DEBUG
>
> log4j.appender.fileLog=org.apache.log4j.FileAppender
> log4j.appender.fileLog.File=TestLogOne.log
> log4j.appender.fileLog.layout=org.apache.log4j.PatternLayout
> log4j.appender.fileLog.layout.ConversionPattern=%m %p %r %c %t %x %% 
> %d %l %C %M %F %L %n
>
> Log4jTest.java
> ------------------------
> package testOne;
> import org.apache.log4j.*;
> import testTwo.*;
> import java.io.*;
>
> public class Log4jTest {
>     static {
>         PropertyConfigurator.configure("logPropOne.properties");
>     }
>
>     private static final Category cat = 
> Category.getInstance(testOne.Log4jTest.class);
>     
>     Log4jTest()     {
>         try
>         {
>             cat.info("Hello ONE");
>             //System.out.println("Calling three from One");
>             testThree.Log4jTestThree.test();
>             //System.out.println("End calling three from One");
>             //System.out.println("Going to other package");
>             testTwo.Log4jTestTwo.test();
>             //System.out.println("Came out from other package");
>             cat.info("Hello ONE:ONE");
>
>         }
>         catch (Exception e)
>         {
>             System.out.println("Except :"+e);
>         }
>     }
>     public static void main(String[] args) throws IOException
>     {
>         new Log4jTest();
>     }
> }
>
> Regards
> Naren
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org