diff --git a/setup_logging.py b/setup_logging.py index b373f82..9222828 100644 --- a/setup_logging.py +++ b/setup_logging.py @@ -18,7 +18,15 @@ def setup_logging(program_name, log_level=logging.DEBUG, terminal_level=logging.INFO, maxBytes=1024*1024*50, backupCount=1): logger = logging.getLogger(program_name) - main_path = __main__.__file__ if hasattr(__main__, '__file__') else __file__ + try: + try: + program_module = __import__(program_name) + except ImportError: + program_module = __import__(program_name.lower()) + main_path = program_module.__file__ + except ImportError: + main_path = __main__.__file__ if hasattr(__main__, '__file__') else __file__ + log_dir = os.path.dirname(os.path.realpath(main_path)) log_path = os.path.join(log_dir, '%s.log' % program_name) handler = logging.handlers.RotatingFileHandler(log_path, maxBytes=maxBytes, backupCount=backupCount)