• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating a log file for my servlet

 
shyamkumar bopannachengalaiah
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had develioped a application where inserting datas from Excel sheet to database.My problem is that when ever a duplicate value is developed either in database or excel sheet , i have to create a log file file and that duplicate value has to written in that log file.I had written the logic for printing the duplicate values in servlet using out.println. but i dont know how to create log file and to write this duplicate values there. Kindly help me.











 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can use Log4j APIs to log the required statements to log file.

Regards,
Amit
 
shyamkumar bopannachengalaiah
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know how can i use log4j. Can you give me a example?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Official Log4j documentation contains details of diffrent ways you can configure log4j (including inside a web application).
 
shyamkumar bopannachengalaiah
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation is not opening . Kindly send me alternate link.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The link I gave directly pointing to the manual page which describes how to configure log4j. If you have downloaded the log4j distribution it also contains that under "site" folder once you extract it. BTW, I don't have any problem with the link.
 
Nandhakumar Soundarrajan
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a similar scenario and in my case I could not use log4j as I need to show the logs of import in a separate file.

In created a separate JAVA class which does importing, so I just call the import method in the class with the filename as parameter which adds all the log values either success or failed (starts with "INFO:" if succeeds and starts with "ERROR:" if fails) and this method returns the arraylist to the calling servlet.

In my servlet I just loop around the arraylist and print it to the brower (which shows only errors) and a log file (which captures all).

Hope this helps.
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This may help you about log4j understanding.

log4j Article
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic