• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Log4j HTML Layout.

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
In your code, change the following statement

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



to

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!