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
Last week, we had the author of
TDD for a Shopping Website LiveProject
. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See
for the agenda and registration link
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
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
Java in General
Log events to a file
Arthur Buliva
Ranch Hand
Posts: 101
posted 13 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 13 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).
permaculture is largely about replacing oil with people. And one tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
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...