• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Log4j HTML Layout.

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I'm new to log4j. I had written the following code in which MyLog.html is created and it contains the 4 rows of messages. When i again run it will overwrite the previous messages ,shown the message with latest timestamp. My requirement is to append the messages.

Can anyone please help me on this ?.

I'll be very much greateful to you.

import org.apache.log4j.*;
import java.io.*;

public class HTMLLog {
static Logger log1 = Logger.getLogger(HTMLLog.class);
public static void main(String[] args) {
BasicConfigurator.configure();
HTMLLayout sl = new HTMLLayout();
WriterAppender app = null;
try
{
app = new WriterAppender();
app.setLayout(sl);
OutputStream ht = new FileOutputStream("MyLog.html");
app.setWriter(new OutputStreamWriter(ht));
app.setImmediateFlush(true);
app.activateOptions();
}
catch(Exception e)
{
System.out.println(" Exception " + e);
}

log1.addAppender(app);
log1.setLevel((Level)Level.DEBUG);
log1.warn("Warn :- low level or equal");
log1.debug("Debug :- Debug is low level");
log1.info("INFO");
}
}
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your code, change the following statement

OutputStream ht = new FileOutputStream("MyLog.html");



to

 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic