• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get log file location inside code  RSS feed

 
Anupam Bhatt
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!