Commit 2ae5f64aa2e72b66ff37ad3c62a6dd8091864985

Authored by hitier
1 parent 89c56528
Exists in rhitier-dev

Change the logging level based on env var DEBUG

Showing 1 changed file with 9 additions and 6 deletions   Show diff stats
@@ -65,22 +65,25 @@ CME_DATE_FMT = "%Y-%m-%dT%H:%MZ" @@ -65,22 +65,25 @@ CME_DATE_FMT = "%Y-%m-%dT%H:%MZ"
65 65
66 # Are we on the SSA instance for ESA? 66 # Are we on the SSA instance for ESA?
67 SSA = environ.get('SSA') == 'true' 67 SSA = environ.get('SSA') == 'true'
68 -DEBUG = environ.get('DEBUG') == 'true'  
69 -# SSA = True 68 +DEBUG = environ.get('DEBUG') in ['true', 'True', 1, '1']
70 69
71 # LOGGING ##################################################################### 70 # LOGGING #####################################################################
72 71
73 LOG_FILE = get_path('run.log') 72 LOG_FILE = get_path('run.log')
74 73
75 hp_logger = logging.getLogger("HelioPropa") 74 hp_logger = logging.getLogger("HelioPropa")
76 -if DEBUG:  
77 - hp_logger.setLevel(logging.DEBUG)  
78 -else:  
79 - hp_logger.setLevel(logging.ERROR) 75 +hp_logger.setLevel(logging.DEBUG)
  76 +
80 logHandler = logging.FileHandler(LOG_FILE) 77 logHandler = logging.FileHandler(LOG_FILE)
81 logHandler.setFormatter(logging.Formatter( 78 logHandler.setFormatter(logging.Formatter(
82 "%(asctime)s - %(levelname)s - %(message)s" 79 "%(asctime)s - %(levelname)s - %(message)s"
83 )) 80 ))
  81 +
  82 +# set file messages depending on env var setting
  83 +if DEBUG:
  84 + logHandler.setLevel(logging.DEBUG)
  85 +else:
  86 + logHandler.setLevel(logging.ERROR)
84 hp_logger.addHandler(logHandler) 87 hp_logger.addHandler(logHandler)
85 88
86 # HARDCODED CONFIGURATION ##################################################### 89 # HARDCODED CONFIGURATION #####################################################