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?

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,869
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,494
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.