Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm working on an application, and adding logging, but now I'm stuck.

I want to allow (not force!) the user to set the location of the logfile.

Basically, my problem is:

  • logger initialization should be the first thing the program does
  • but I can't initialize the logger until I determine where the user wants the log to be saved
  • determining where the log should be saved ... is a process that should be logged

How is this problem solved? Are log file locations not user-customizable? Is log output buffered until a logfile is set?

share|improve this question
    
This is some sort of individual desktop or mobile app and not something being installed by an IT person on a server? If so, don't bother the user. –  JeffO Dec 8 '11 at 1:02
add comment

3 Answers

up vote 4 down vote accepted

Add the location of the log file as a value in a configuration file. That way the user can configure this value before they run your application and your application can simply read it from the configuration file. Include a default value in your configuration file in case the user does not modify the value.

share|improve this answer
    
Use a reasonable default location, such as the location of the application itself, to store the log file. –  Bernard Dec 7 '11 at 22:00
2  
@MattFenwick - Normally, you'd try whatever log location is configured and, if that fails, either abort when the application starts or default to some location that you know will be valid. Which of these you choose depends on the application-- an enterprise database, for example, should probably abort if the destination for an audit log is inaccessible. A common line of business client application should probably just write to a default location. –  Justin Cave Dec 7 '11 at 22:08
add comment

The decision where to store the logfile should have to be made by you in the first place (to get things initialized). Then offer the user the possibility if he wants to change he could (but does not have to).

You wrote that you want the user to be able to set the location of the log file. You propably have your reasons to do so, but: Consider if you realy want every user to have to set the logfile location.

share|improve this answer
add comment

Who is the log for? If it's for you as a developer, don't let the user set it (ie: don't force them to think about something they don't care about). If it is for the user to consult later, then put it in a default location and let the user change it later.

Whatever you do, do not, for the love of all that is holy, start your program with a dialog box "Where do you want your log file to go?" or require an environment variable $LOG_PLACE to be defined. The only exception to this might be if your program's sole purpose in life was as a logger to something else.

Point is, be nice to your users, make the dang thing just work. If someone cares to muck about and change a default you can let them, but make it work out of the box for the 99% of users who will never, ever, ever need to change where log file is saved at.

share|improve this answer
    
Excellent points. I'm guessing this isn't some server app. –  JeffO Dec 8 '11 at 1:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.