Thanks for your help. I wrote a new design class which exntends the existing
PatternLayout class.
In this class you can override the format(LogginEvent event) method to whatever
you want.
Here is my example, perhaps it could be helpful for someone else.
public class Log4JMemoryLayout extends PatternLayout
{
public String format(LoggingEvent event)
{
String temp = super.format(event);
if(event.getLevel().isGreaterOrEqual(Level.DEBUG))
{
StringBuffer sbuf = new StringBuffer();
double free = Runtime.getRuntime().freeMemory() / 1024d / 1024d;
double max = Runtime.getRuntime().maxMemory() / 1024d / 1024d;
double total = Runtime.getRuntime().totalMemory() / 1024d / 1024d;
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMinimumIntegerDigits(3);
nf.setMaximumIntegerDigits(4);
nf.setMinimumFractionDigits(3);
nf.setMaximumFractionDigits(3);
sbuf.append("[Free: " + nf.format(free) + " MB; ");
sbuf.append("Total: " + nf.format(total) + " MB; ");
sbuf.append("Max: " + nf.format(max) + " MB] ");
return sbuf.toString() + temp;
}
else
{
return temp;
}
}
}
-- C.P.
-----Ursprüngliche Nachricht-----
Von: James Stauffer [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 4. Januar 2007 18:24
An: Log4J Users List
Betreff: Re: Log memory usage of the java virtual machine
You could make your own appender and add the info there or make your
own layout class to add support for including it in the output.
On 1/4/07, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm searching for a solution to add the memory usage of the java virtual
> machine to every log4j entry. At the moment I can access only manually the
> memory usage with the help of:
>
> double free = Runtime.getRuntime().freeMemory() / 1024d / 1024d;
> double max = Runtime.getRuntime().maxMemory() / 1024d / 1024d;
> double total = Runtime.getRuntime().totalMemory() / 1024d / 1024d;
>
> I'm using the logger at many different positions so it would be a very bad
> solution to add these values every time manually to the logger-output. Is it
> possible to add these values automatically to every logger-output?
>
> --C.P.
>
>
--
James Stauffer http://www.geocities.com/stauffer_james/
Are you good? Take the test at http://www.livingwaters.com/good/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]