Skip to content

Commit

Permalink
create log directory if one doesn't already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bikegeek committed Mar 31, 2024
1 parent 7b3b2c6 commit 18429ab
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions metplotpy/plots/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
__author__ = 'Minna Win'

import argparse
from typing import Tuple
import sys
import getpass
import os
import logging
import gc
import re
Expand Down Expand Up @@ -316,6 +315,13 @@ def get_common_logger(log_level, log_filename):
currently in use by a plot type.
'''

# If directory for logfile doesn't exist, create it
log_dir = os.path.dirname(log_filename)
try:
os.makedirs(log_dir, exist_ok=True)
except OSError:
pass

# Supported log levels.
log_level = log_level.upper()
log_levels = {'DEBUG': logging.DEBUG, 'INFO': logging.INFO,
Expand All @@ -338,7 +344,7 @@ def get_common_logger(log_level, log_filename):
datefmt='%Y-%m-%d %H:%M:%S',
filename=log_filename,
filemode='w')
mpl_logger = logging.getLogger(name='matplotlib').setLevel(logging.CRITICAL)
logging.getLogger(name='matplotlib').setLevel(logging.CRITICAL)
common_logger = logging.getLogger(__name__)
f = cf()
common_logger.addFilter(f)
Expand Down

0 comments on commit 18429ab

Please sign in to comment.