Skip to content

Commit

Permalink
Merged in cbillington/labscript_utils/bugfix (pull request labscript-…
Browse files Browse the repository at this point in the history
…suite#7)

setup_logging use program name instead of __main__ location for log file location

Approved-by: Philip Starkey <[email protected]>
  • Loading branch information
philipstarkey committed May 22, 2017
2 parents d130bbe + d35a914 commit 713920e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion setup_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 713920e

Please sign in to comment.