mherrmann / fbs-tutorial

Tutorial for creating Python/Qt GUIs with fbs
https://build-system.fman.io
GNU General Public License v3.0
1.95k stars 161 forks source link

Guidance for Properly Logging #33

Open j9ac9k opened 4 years ago

j9ac9k commented 4 years ago

It would be good if the tutorial provided some guidance on how to setup logging, especially for macOS, where the logger FileHandler only takes relative paths, and thus attempts to write in a read-only portion of the app bundle.

On Linux, the logging.handlers.FileHandler appeared to work fine (wrote to the user home directory if I remember right), I have not tested on Windows.

Thanks for the awesome package!

mherrmann commented 4 years ago

Thank you for the suggestion. I want to keep fbs's docs to the minimum, because the longer they get, the more difficult they become to read (by fbs users like yourself), and to maintain for me. I feel like the logging questions you describe are beyond the scope of fbs's documentation, as this isn't strictly a feature of fbs.

Having said that, I don't think FileHandler only takes relative paths. Without having tested it, I think you should be able to log to the home directory with the following code on all OSs:

from os import makedirs
from os.path import expanduser
from logging import FileHandler
makedirs(expanduser('~/.myapp'), exist_ok=True)
handler = FileHandler(expanduser('~/.myapp/myapp.log'))

Hope this helps.