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:
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:
Java in General
java.util.Logger creating multiple log files
Anant Jagania
Ranch Hand
Posts: 49
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I created a My Logger class which holds object of java.util.Logger and in the constructor i am adding FileHandler to Logger.
Now this logger i used in all my class for logging purpose.
It seems that it is creating new new log files every time. When I run the my application it creates three log files at the same time.
Please let me know how to over come this.
Thanks,
Anant
David Newton
Author
Posts: 12617
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I think it'd make sense to post the actual code (and configuration, if any) you're using.
Anant Jagania
Ranch Hand
Posts: 49
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is the code
import java.io.IOException; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; public class MYLogger { private Logger logger = null; private MYLogger(String className) throws IOException { logger = Logger.getLogger(className); logger.addHandler(new FileHandler("log.txt")); } public static MYLogger getLogger(String className) { try { return new MYLogger(className); } catch (IOException ex) { Logger.getLogger(MYLogger.class.getName()).log(Level.SEVERE, "There was some issue creating the file handler for Logger", ex); return null; } } public void log(Level level, String msg, Object param1) { logger.log(level, msg, param1); } public void log(Level level, String msg) { logger.log(level, msg); } }
Pat Farrell
Rancher
Posts: 4803
7
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you are having to change your code to make it work the way you like, I suggest you take a quick look at Apache's log4j
It is widely used, more flexible, and there is an active support mailing list.
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to see log entries in Google App engine
Tool for analyzing XML-Formatter log
Dealing with exception messages.
java.util.logger OutOfMemoryError
Create user wise Log file.
More...