From 2a84ee47e8ab48bbd49bf32aa7d61311b1378d4c Mon Sep 17 00:00:00 2001 From: Ace Date: Mon, 7 Dec 2020 00:23:42 +0100 Subject: [PATCH] fixing issues with log file on readthedocs --- inkycal/main.py | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/inkycal/main.py b/inkycal/main.py index d1fb48d..69450fd 100644 --- a/inkycal/main.py +++ b/inkycal/main.py @@ -41,22 +41,31 @@ except ImportError: stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.ERROR) -# Save all logs to a file, which contains more detailed output -logging.basicConfig( - level = logging.INFO, - format='%(asctime)s | %(name)s | %(levelname)s: %(message)s', - datefmt='%d-%m-%Y %H:%M:%S', - handlers=[ +on_rtd = os.environ.get('READTHEDOCS') == 'True' +if on_rtd: + logging.basicConfig( + level = logging.INFO, + format='%(asctime)s | %(name)s | %(levelname)s: %(message)s', + datefmt='%d-%m-%Y %H:%M:%S', + handlers=[stream_handler]) + +else: + # Save all logs to a file, which contains more detailed output + logging.basicConfig( + level = logging.INFO, + format='%(asctime)s | %(name)s | %(levelname)s: %(message)s', + datefmt='%d-%m-%Y %H:%M:%S', + handlers=[ - stream_handler, # add stream handler from above + stream_handler, # add stream handler from above - RotatingFileHandler( # log to a file too - f'{top_level}/logs/inkycal.log', # file to log - maxBytes=2097152, # 2MB max filesize - backupCount=5 # create max 5 log files - ) - ] - ) + RotatingFileHandler( # log to a file too + f'{top_level}/logs/inkycal.log', # file to log + maxBytes=2097152, # 2MB max filesize + backupCount=5 # create max 5 log files + ) + ] + ) # Show less logging for PIL module logging.getLogger("PIL").setLevel(logging.WARNING)