| 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
|
|
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
|
 |
 |
|
|
subject: How to get log file location inside code
|
|
|