Use different default log_path under Windows

This commit is contained in:
2Shirt 2019-07-13 17:23:35 -06:00
parent b98397d491
commit 8b4daa507b
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -61,12 +61,21 @@ def update_log_path(dest_dir, dest_filename=''):
def start(config=None): def start(config=None):
"""Configure and start logging using safe defaults.""" """Configure and start logging using safe defaults."""
log_dir = '{}/Logs/'.format(os.path.expanduser('~')) if os.name == 'nt':
log_path = '{}/{}_{}.log'.format( log_path = '{drive}/{short}/Logs/{date}/{full}/log_{datetime}.log'.format(
log_dir, drive=os.environ.get('SYSTEMDRIVE', 'C:'),
cfg.main.KIT_NAME_FULL, short=cfg.main.KIT_NAME_SHORT,
time.strftime('%Y-%m-%d_%H%M%S%z'), date=time.strftime('%y-%m-%d'),
) full=cfg.main.KIT_NAME_FULL,
datetime=time.strftime('%Y-%m-%d_%H%M%S%z'),
)
else:
log_path = '{home}/Logs/{full}_{datetime}.log'.format(
home=os.path.expanduser('~'),
full=cfg.main.KIT_NAME_FULL,
datetime=time.strftime('%Y-%m-%d_%H%M%S%z'),
)
log_path = pathlib.Path(log_path).resolve()
root_logger = logging.getLogger() root_logger = logging.getLogger()
# Safety checks # Safety checks
@ -76,7 +85,7 @@ def start(config=None):
raise UserWarning('Logging already started.') raise UserWarning('Logging already started.')
# Create log_dir # Create log_dir
os.makedirs(log_dir, exist_ok=True) os.makedirs(log_path.parent, exist_ok=True)
# Config logger # Config logger
logging.basicConfig(filename=log_path, **config) logging.basicConfig(filename=log_path, **config)