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 Johan Sandgren <js...@svep.se> on 2008/10/08 10:19:36 UTC

Dual logging problem - outofmemoryerror... heap space

Hi,

Need advice from professionals here... I'm stuck! :(

I'm using log4j, and my logs are rotating quite fast, so if an error occurs, for example in the middle of the night, it will not be present in the log in the morning when I arrive to check for errors.

So I decided to extract the errors live, when they occur, and make them go to another file.
But since errors just on their own does not say much of where the program were and what was the variables right then, I'd also like to attach some history before the error in the error.log-file.

So I wrote a class to support this feature. It's a spy really. It's attaching to an existing logger, and adding another appender, which I use to create history and outputting to another error.log-file when I need to.


A little more details on the spyclass are:

I'm calling my usual logger X, and I've created another loggerclass Y, which attaches another appender on my X.

For each logger call with X, I also call my Y which is getting the string too, because it's snooping on X, via this appender I added. Y is also keeping a circularbuffer of history of all logging it gets.
When Y is called with error, fatal or warn, it will do a dump of the history and lastly, the erranous line, and all this to another file, error.log.

That way I will get my usual log in blabla.log, and for each warn, error /fatal, I get a few lines of history + the error/warn/fatal-line that is to be noticed.


My problem:
BUT, I get out of heapmemory when using it after a while.
I cannot find the error causing it. Mayber I'm misusing the appender or log4j?

I've attached the historymaking class "ErrorLogger.java", and an example (test.java) of how the calls are made.



Exception in thread "Thread-5" java.lang.OutOfMemoryError: Java heap space
        at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:99)
        at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:393)
        at java.lang.StringBuffer.append(StringBuffer.java:225)
        at java.io.StringWriter.write(StringWriter.java:79)
        at org.apache.log4j.helpers.QuietWriter.write(QuietWriter.java:47)
        at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:301)
        at org.apache.log4j.WriterAppender.append(WriterAppender.java:159)
        at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:230)
        at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:65)
        at org.apache.log4j.Category.callAppenders(Category.java:203)
        at org.apache.log4j.Category.forcedLog(Category.java:388)
        at org.apache.log4j.Category.debug(Category.java:257)

        at com.sttcare.alarmSwitch.JmsTester.activeMqIsUp(JmsTester.java:88) calls connection.stop(); So it really has nothing with log4j, I guess the heap is just ended right then.

        at com.sttcare.alarmSwitch.systemWatch.ProgramChecker.activeMQWorks(ProgramChecker.java:143)
        at com.sttcare.alarmSwitch.systemWatch.ProgramChecker.run(ProgramChecker.java:119)
        at java.lang.Thread.run(Thread.java:595)


Seems to me something is exandCapacity too much...

/Johan

_______________
Johan Sandgren
Svep Design Center AB
Phone +46 46 192 722
Mobile +46 70 173 4152
Box 1233, 221 05 Lund, Sweden
E-mail   jsa@svep.se
Website www.svep.se<http://www.svep.se/>


SV: Dual logging problem - outofmemoryerror... heap space

Posted by Johan Sandgren <js...@svep.se>.
True, but since we are using flash-drives (4GB), no gigantic harddrives, we have strict limitations of storage. I can only use 5MB for the rolling logfiles :-)

That's why I needed to invent this solution, keeping the normals logs rolling, and keeping a history rolling to tag along each error/fatal/warn I get.

:-)

-----Ursprungligt meddelande-----
Från: Jukka Zitting [mailto:jukka.zitting@gmail.com]
Skickat: den 8 oktober 2008 10:34
Till: Log4J Developers List
Ämne: Re: Dual logging problem - outofmemoryerror... heap space

Hi,

On Wed, Oct 8, 2008 at 10:19 AM, Johan Sandgren <js...@svep.se> wrote:
> I'm using log4j, and my logs are rotating quite fast, so if an error occurs,
> for example in the middle of the night, it will not be present in the log in
> the morning when I arrive to check for errors.
>
> So I decided to extract the errors live, when they occur, and make them go
> to another file.

Wouldn't an easier solution have been to just decrease the log rotation rate?

BR,

Jukka Zitting

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


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


Re: Dual logging problem - outofmemoryerror... heap space

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Wed, Oct 8, 2008 at 10:19 AM, Johan Sandgren <js...@svep.se> wrote:
> I'm using log4j, and my logs are rotating quite fast, so if an error occurs,
> for example in the middle of the night, it will not be present in the log in
> the morning when I arrive to check for errors.
>
> So I decided to extract the errors live, when they occur, and make them go
> to another file.

Wouldn't an easier solution have been to just decrease the log rotation rate?

BR,

Jukka Zitting

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