Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
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:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Java in General
Log events to a file
Arthur Buliva
Ranch Hand
Posts: 101
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Am intending to log events occurring in a
Java
app to a file. Code:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.IOException; import java.util.Timer; import java.util.TimerTask; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; //import javax.swing.Timer; /** * * @author arthur */ public class Daemon { public static void main(String[] args) { int delay = 0000; // delay for 0 sec. int interval = 1000; // iterate every sec. Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { // Task here ... log(Level.INFO, "Hello World"); } }, delay, interval); } private static void log(Level level, String message) { try { boolean append = true; FileHandler logHandler = new FileHandler("daemon.log", append); Logger log = Logger.getLogger(Daemon.class.getName()); log.addHandler(logHandler); log.log(level, message); } catch (IOException ex) { log(Level.SEVERE, String.valueOf(ex)); } catch (SecurityException ex) { log(Level.SEVERE, String.valueOf(ex)); } } }
works fine, but am having multiple files yet the FileHandler has been implicitly asked to append to the log file. What am I doing wrong?
Francesc Martinez
Greenhorn
Posts: 24
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I don't know, but you could use Log4J instead (directly or through Commons Logging).
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
java.util.Logger creating multiple log files
How do I go about making my own Yahoo Messenger?
iText: Digital signature
error while reading objects from file
Writing logs to a single file from Multiple Classes
More...