aspose file tools
The moose likes Java in General and the fly likes How to get log file location inside code Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to get log file location inside code" Watch "How to get log file location inside code" New topic
Author

How to get log file location inside code

Anupam Bhatt
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
I use the java logger in my application, and define the log file location in the application's properties file.
Now my requirement is to know where is the log file location inside my app, for which i was looking for some api's in the java.util.logging classes but cant seem to find one.

Is there a way to get the log file location inside your code?

I dont want to get the log file pattern "%t/mylog.txt" and then deduce from the pattern to know where the log file is in my app.

To me it looks like a very common usecase, any ideas?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

Common use case? I don't think so. You shouldn't even expect that logging is going to a file, let alone being able to find out the name of that file. Violates "separation of concerns".

But let's go back a step and find out why you need to do this.
Anupam Bhatt
Ranch Hand

Joined: Mar 12, 2004
Posts: 81
ok, so why i need to do this is because i want to display to the user "For detailed description of the exception please look in to the log file at c:\foo\bar\blah.txt"

Without this the user has to look in to the properties file to find where the log file could be located !

I hope that explains the scenario.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I guess you could read the very same properties file from code. I agree with Paul that this gives you a nasty bit of coupling ... the app has to know quite a bit about the logger and what properties file to read. Maybe a third class could publish the logfile location to all interested parties?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to get log file location inside code
 
Similar Threads
Writing a log file for my servlet
DTD location
how to know the location of log file set in log4jproperty file
Open a file in a jsp page
read permission to a file created by weblogic