2

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?

  • 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 08 '11 at 01:02

3 Answers3

3

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.

Bernard
  • 8,859
  • 31
  • 40
  • Use a reasonable default location, such as the location of the application itself, to store the log file. – Bernard Dec 07 '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 07 '11 at 22:08
1

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.

anon
  • 1,474
  • 8
  • 8
0

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.

Manuel Schmidt
  • 163
  • 1
  • 8