This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Logfile from different classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Logfile from different classes" Watch "Logfile from different classes" New topic

Logfile from different classes

dave tuazon

Joined: Feb 26, 2002
Posts: 4
How do i create a logfile that can be accessed from different classes. I only want to use one logfile which will be open while the application i make is running. It will only close when i close my application. I have many classes in different files. What can i do to make the Log class a public accessible class to all the others.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
You could apply the Singleton pattern for the Logger class (all code would use Logger.getInstance(), and get a reference to the same Logger instance).
This Logger class should be able to handle input from different threads at once, to avoid intermixed output in the file.
Hope this helps.
Don't get me started about those stupid light bulbs.
subject: Logfile from different classes
Similar Threads
log messages
Initializing log4j within Eclipse on a per project (Dynamic Web Project) basis
How to limit the size of a log file?
re: help appreciated
log4j - no output to .log file