Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Beginning Java
Logging in servlet
Max Vaha
Greenhorn
Posts: 29
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Good evening everyone!
I want to log some events in my "HelloWorld"
servlet
using java.util.logging.Logger (to write "init" to a text file). But I have found only SE examples using Google((.
Can anyone give me an advise?
K.Suresh Kumar
Ranch Hand
Posts: 41
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
The following code example will be useful for you.....
Writing Log Records to a Log File
To make a logger write log records to a file, you need to add a file handler to the logger.
try {
// Create a file handler that write log record to a file called my.log
FileHandler handler = new FileHandler("my.log");
// Add to the desired logger
Logger logger = Logger.getLogger("com.mycompany");
logger.addHandler(handler);
} catch (IOException e) {
}
By default, a file handler overwrites the contents of the log file each time it is created. This example creates a file handler that appends.
try {
// Create an appending file handler
boolean append = true;
FileHandler handler = new FileHandler("my.log", append);
// Add to the desired logger
Logger logger = Logger.getLogger("com.mycompany");
logger.addHandler(handler);
} catch (IOException e) {
}
Regards,
Suresh Kumar.K
Christophe Verré
Sheriff
Posts: 14691
16
I like...
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
There's already a log method in the GenericServlet class (which your servlet extends).
[My Blog]
All roads lead to JavaRanch
Max Vaha
Greenhorn
Posts: 29
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
K.Suresh Kumar,
thank you very much! Works perfectly.
Christophe Verre, thanks for your answer, but I need my own log file, GenericServlet is unsuitable for me.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Problem with MultipartFormDataRequest
How to find out cgi variables in java?
servlet doesn't invoke (page not found displayed)
Jsp to pdf
Using TLD in JSP
More...