Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding check for log file/log directory existence #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion spotui/src/Logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@
import os

user_config_dir = os.path.expanduser("~")
logging.basicConfig(filename=user_config_dir + '/.cache/spotui.log', filemode='w',
filename = user_config_dir + "/.cache/spotui.log"
if not os.path.exists(os.path.dirname(filename)):
try:
os.makedirs(os.path.dirname(filename))
except OSError as exc: # prevent race condition
if exc.errno != errno.EEXIST:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't import errno

raise

# if log file doesn't exist
if not os.path.isfile(filename):
with open('sample.csv', 'w') as creating_new_log_file:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sample.csv?

pass

logging.basicConfig(filename, filemode='w',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging.basicConfig doesn't take any position args. If you look at the original code (or just check the function signature) you'll see it expects filename as a keyword arg. I'd suggest running your code at least once just to sanity check this kind of thing

format='%(name)s - %(levelname)s - %(message)s')