I've been working on a program, with Disch's help, that is basically a work-around for a problem I'm having with my laptop. It's nearly complete and all I've left to do is finish off the logging system. It's my first time writing a program that actually outputs a log file, and especially so on a linux system.
Currently, logging is turned on by using the --log /path/to/file.log or -l /path/to/file.log switches. In this manner, I allow the user to specify where the log file goes. But I don't want to leave it to the user to give a valid file path. I learned a long time ago to never trust the user. lol. I'm wondering, is it sufficiently safe to open the path they give, and then test to make sure it opened? Or do I need to incorporate some sort of safe-guard against a garbage file path? How could that be done? I'm also thinking about making a default so that if the user only enters the switch without specifying a path, it'll at least put a log somewhere.
My question regarding this: Where? Where should I set the default log to? I could put it in /var/log, but is that proper? Would it even write without being run as root? I could put it in /home/$USER/, but but I'm a neat-freak when it comes to my file-system, and to me that just feels dirty. I could do /home/$USER/.log, at least then it'd be in a place meant to collect logs, but a dumb or new user to linux would never find it, since it's in a hiddden folder where they'd not think to look assuming they even knew it was there. If I put it in /home/$USER/log, then it's not hidden anymore, but we're back to a potentially dirty file system, especially because I don't think any other programs put logs there.
Any suggestions on either of these points would be a big help. Thank you.
EDIT: I forgot to mention that this is a headless program meant to be called by a keybind in either GNOME or KDE, whichever the user is running. That is why I feel logging is so important.
If you ask 10 different programmers, you are going to get 10 different answers on this - *nix-variants don't even agree where log files should go (the location even changes sometimes with releases).
There is no right answer to your questions: it comes down to your preferences. If you want guidance, look at where your OS is storing the log files of similar programs and follow that protocol, if it fits into what you are doing.
Thank you all very much. I've decided the log, by default, would be a hidden file in ~/ for now. That will probably change in later versions if the community that my program is aimed at shows support for keeping it going. If you're interested in my code or in what my program does, I have a source package, description, and README up at http://ubuntuforums.org/showthread.php?t=1607425.