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 Simon Park <si...@yahoo.co.uk> on 2009/03/19 15:06:56 UTC

Re: Custom Appender works fine with rootlogger, but not when logger specified

Hi,

Take a look at the http://www.simonsite.org.uk/javadoc/org/apache/log4j/appender/TimeAndSizeRollingAppender.html.  Source is available in the JAR at http://www.simonsite.org.uk/resources/lib/log4j-rolling-appender.jar.  This appender does a similar thing to your custom appender by the sounds of it.

Simon




________________________________
From: Guy <gu...@gmail.com>
To: log4j-user@logging.apache.org
Sent: Thursday, 19 March, 2009 9:48:51
Subject: Custom Appender works fine with rootlogger, but not when logger  specified

Hi,

I have written a custom appender that adds file rotation and zipping
of the rotated files. Some other custom functionality is added. What I
do is: when a file has reached a certain size, I close the file,
rename it and compress it. After the rename, I reset the file. The
renaming of the file is where it all goes wrong.


Everything works fine if I stick to using the rootLogger:

<Defining of our custom appender>

log4j.rootLogger=INFO, ddm

#THIS WORKS FINE
#log4j.logger.mylogger=INFO


#THIS DOES NOT WORK FINE. Note That we do not even write to this logger (class)
log4j.logger.be.package=INFO, mylogger


SO for some reason, using the line "log4j.logger.be.package=INFO,
mylogger" creates an object that prevents the rename from taking
place.

I have looked at the RollingFileAppender about closing the
file/writing to the stream, but as far as I can see, I do the same. I
could also rewrite my custom appender starting from the
RollingFileAppender, but that is something I want to prevent

Any help would be apreciated

Guy

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


      

RE: Custom Appender works fine with rootlogger, but not when logger specified

Posted by Matt Brown <Ma...@citrixOnline.com>.
It sounds like instead of using a logger named "com.company.blah.MyClass", your code is asking log4j for a logger named simply "MyClass".

Therefore when your log4j.properties configuration refers to the logger named "MyClass", it works as you expect; but when you attempt to configure the logger named "com.company.blah.MyClass", nothing happens - because no code is sending any log messages to a logger with that name.

 

-----Original Message-----
From: Guy [mailto:guy.van.tilborgh@gmail.com] 
Sent: Thursday, March 19, 2009 10:16 AM
To: Log4J Users List
Subject: Re: Custom Appender works fine with rootlogger, but not when logger specified

Thanks Simon,

but my problem was caused by the following lines during activateOptions():

//set the name to the className as name of the appender.
//This will always be the name of the actual class (I have more than one appender, some extending the other) String classname = this.getClass().getName(); classname = classname.substring(classname.lastIndexOf(".") +1); this.setName(classname);

I don't even know anymore why I thought this would be a good idea, but ommenting the code solved the problem.

I am curious how that code was the cause of the problem, but the problem itself is solved

Guy



On Thu, Mar 19, 2009 at 3:06 PM, Simon Park <si...@yahoo.co.uk> wrote:
> Hi,
>
> Take a look at the http://www.simonsite.org.uk/javadoc/org/apache/log4j/appender/TimeAndSizeRollingAppender.html.  Source is available in the JAR at http://www.simonsite.org.uk/resources/lib/log4j-rolling-appender.jar.  This appender does a similar thing to your custom appender by the sounds of it.
>
> Simon
>
>
>
>
> ________________________________
> From: Guy <gu...@gmail.com>
> To: log4j-user@logging.apache.org
> Sent: Thursday, 19 March, 2009 9:48:51
> Subject: Custom Appender works fine with rootlogger, but not when 
> logger  specified
>
> Hi,
>
> I have written a custom appender that adds file rotation and zipping 
> of the rotated files. Some other custom functionality is added. What I 
> do is: when a file has reached a certain size, I close the file, 
> rename it and compress it. After the rename, I reset the file. The 
> renaming of the file is where it all goes wrong.
>
>
> Everything works fine if I stick to using the rootLogger:
>
> <Defining of our custom appender>
>
> log4j.rootLogger=INFO, ddm
>
> #THIS WORKS FINE
> #log4j.logger.mylogger=INFO
>
>
> #THIS DOES NOT WORK FINE. Note That we do not even write to this 
> logger (class) log4j.logger.be.package=INFO, mylogger
>
>
> SO for some reason, using the line "log4j.logger.be.package=INFO, 
> mylogger" creates an object that prevents the rename from taking 
> place.
>
> I have looked at the RollingFileAppender about closing the 
> file/writing to the stream, but as far as I can see, I do the same. I 
> could also rewrite my custom appender starting from the 
> RollingFileAppender, but that is something I want to prevent
>
> Any help would be apreciated
>
> Guy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>

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


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


RE: Serialize Unserialise LoggingEvent..

Posted by Michael Erskine <mi...@ketech.com>.
> From: Chandresh Turakhia [mailto:chandresh.turakhia@bhartitelesoft.com]
> Subject: Serialize Unserialise LoggingEvent..

> Has any one tried Serializing and Deserializing LoggingEvent. If so can
> u share experiences plz..

Sure, serialization of LoggingEvent works fine here. See the source of org.apache.log4j.net.SocketHubAppender for a good example of management of the stream with the appropriate flush and reset methods.

Regards,
Michael Erskine.


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


Serialize Unserialise LoggingEvent..

Posted by Chandresh Turakhia <ch...@bhartitelesoft.com>.
Dear all :

I know there are trainsient variables in LoggingEvent but I tried serializing and deserializing to file.
Only first LoggingEvent is deserialized and after that I get

java.io.StreamCorruptedException
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1326)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
        at test2.main(test2.java:33)

Has any one tried Serializing and Deserializing LoggingEvent. If so can u share experiences plz..

Regards
Chand

-----Original Message-----
From: Guy [mailto:guy.van.tilborgh@gmail.com]
Sent: Thursday, March 19, 2009 7:46 PM
To: Log4J Users List
Subject: Re: Custom Appender works fine with rootlogger, but not when logger specified

Thanks Simon,

but my problem was caused by the following lines during activateOptions():

//set the name to the className as name of the appender.
//This will always be the name of the actual class (I have more than
one appender, some extending the other)
String classname = this.getClass().getName();
classname = classname.substring(classname.lastIndexOf(".") +1);
this.setName(classname);

I don't even know anymore why I thought this would be a good idea, but
ommenting the code solved the problem.

I am curious how that code was the cause of the problem, but the
problem itself is solved

Guy



On Thu, Mar 19, 2009 at 3:06 PM, Simon Park <si...@yahoo.co.uk> wrote:
> Hi,
>
> Take a look at the http://www.simonsite.org.uk/javadoc/org/apache/log4j/appender/TimeAndSizeRollingAppender.html.  Source is available in the JAR at http://www.simonsite.org.uk/resources/lib/log4j-rolling-appender.jar.  This appender does a similar thing to your custom appender by the sounds of it.
>
> Simon
>
>
>
>
> ________________________________
> From: Guy <gu...@gmail.com>
> To: log4j-user@logging.apache.org
> Sent: Thursday, 19 March, 2009 9:48:51
> Subject: Custom Appender works fine with rootlogger, but not when logger  specified
>
> Hi,
>
> I have written a custom appender that adds file rotation and zipping
> of the rotated files. Some other custom functionality is added. What I
> do is: when a file has reached a certain size, I close the file,
> rename it and compress it. After the rename, I reset the file. The
> renaming of the file is where it all goes wrong.
>
>
> Everything works fine if I stick to using the rootLogger:
>
> <Defining of our custom appender>
>
> log4j.rootLogger=INFO, ddm
>
> #THIS WORKS FINE
> #log4j.logger.mylogger=INFO
>
>
> #THIS DOES NOT WORK FINE. Note That we do not even write to this logger (class)
> log4j.logger.be.package=INFO, mylogger
>
>
> SO for some reason, using the line "log4j.logger.be.package=INFO,
> mylogger" creates an object that prevents the rename from taking
> place.
>
> I have looked at the RollingFileAppender about closing the
> file/writing to the stream, but as far as I can see, I do the same. I
> could also rewrite my custom appender starting from the
> RollingFileAppender, but that is something I want to prevent
>
> Any help would be apreciated
>
> Guy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>

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


This e-mail and all material transmitted with it are for the use of the intended recipient(s) ONLY and contains confidential and/or privileged information. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies and the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken pursuant to the contents of the present e-mail is strictly prohibited and is unlawful.
The recipient acknowledges that Bharti Telesoft Limited or its management or directors, are unable to exercise control or ensure the integrity over /of the contents of the information contained in e-mail. Any views expressed herein are those of the individual sender only and no binding nature of the contents shall be implied or assumed unless the sender does so expressly with due authority of Bharti Telesoft Limited. E-mail and any contents transmitted with it are prone to viruses and related defects despite all efforts to avoid such by Bharti Telesoft Limited.

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


Re: Custom Appender works fine with rootlogger, but not when logger specified

Posted by Guy <gu...@gmail.com>.
Thanks Simon,

but my problem was caused by the following lines during activateOptions():

//set the name to the className as name of the appender.
//This will always be the name of the actual class (I have more than
one appender, some extending the other)
String classname = this.getClass().getName();
classname = classname.substring(classname.lastIndexOf(".") +1);
this.setName(classname);

I don't even know anymore why I thought this would be a good idea, but
ommenting the code solved the problem.

I am curious how that code was the cause of the problem, but the
problem itself is solved

Guy



On Thu, Mar 19, 2009 at 3:06 PM, Simon Park <si...@yahoo.co.uk> wrote:
> Hi,
>
> Take a look at the http://www.simonsite.org.uk/javadoc/org/apache/log4j/appender/TimeAndSizeRollingAppender.html.  Source is available in the JAR at http://www.simonsite.org.uk/resources/lib/log4j-rolling-appender.jar.  This appender does a similar thing to your custom appender by the sounds of it.
>
> Simon
>
>
>
>
> ________________________________
> From: Guy <gu...@gmail.com>
> To: log4j-user@logging.apache.org
> Sent: Thursday, 19 March, 2009 9:48:51
> Subject: Custom Appender works fine with rootlogger, but not when logger  specified
>
> Hi,
>
> I have written a custom appender that adds file rotation and zipping
> of the rotated files. Some other custom functionality is added. What I
> do is: when a file has reached a certain size, I close the file,
> rename it and compress it. After the rename, I reset the file. The
> renaming of the file is where it all goes wrong.
>
>
> Everything works fine if I stick to using the rootLogger:
>
> <Defining of our custom appender>
>
> log4j.rootLogger=INFO, ddm
>
> #THIS WORKS FINE
> #log4j.logger.mylogger=INFO
>
>
> #THIS DOES NOT WORK FINE. Note That we do not even write to this logger (class)
> log4j.logger.be.package=INFO, mylogger
>
>
> SO for some reason, using the line "log4j.logger.be.package=INFO,
> mylogger" creates an object that prevents the rename from taking
> place.
>
> I have looked at the RollingFileAppender about closing the
> file/writing to the stream, but as far as I can see, I do the same. I
> could also rewrite my custom appender starting from the
> RollingFileAppender, but that is something I want to prevent
>
> Any help would be apreciated
>
> Guy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>
>

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