Changeset 64ca561 in sasview
- Timestamp:
- Apr 5, 2017 7:24:44 AM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- ebb0a55
- Parents:
- 01febaf
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
run.py
r05a9d29 r64ca561 17 17 import sys 18 18 import imp 19 import logging 20 import logging.config 21 19 22 from contextlib import contextmanager 20 23 from os.path import abspath, dirname, join as joinpath 21 24 22 class TeeStream:23 def __init__(self, filename):24 self.logfile = open(filename, 'a')25 self.console = sys.stderr26 def write(self, buf):27 self.logfile.write(buf)28 self.console.write(buf)29 25 30 def tee_logging(): 31 import logging 32 stream = TeeStream(os.path.join(os.path.expanduser("~"), 'sasview.log')) 33 logging.basicConfig(level=logging.INFO, 34 format='%(asctime)s %(levelname)s %(message)s', 35 stream=stream) 26 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'sasview/logging.ini') 27 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=True) 28 logger = logging.getLogger(__name__) 36 29 30 def update_all_logs_to_debug(logger): 31 ''' 32 This updates all loggers and respective handlers to DEBUG 33 ''' 34 for handler in logger.handlers or logger.parent.handlers: 35 handler.setLevel(logging.DEBUG) 36 for name,_ in logging.Logger.manager.loggerDict.items(): 37 logging.getLogger(name).setLevel(logging.DEBUG) 38 37 39 def addpath(path): 38 40 """ … … 152 154 153 155 if __name__ == "__main__": 156 update_all_logs_to_debug(logger) 154 157 prepare() 155 tee_logging()156 158 from sas.sasview.sasview import run 157 159 run() 160 -
sasview/logging.ini
r9c0f3c17 r64ca561 3 3 ################################### LOGGING ################################### 4 4 ############################################################################### 5 # Main logger for SASView 5 6 7 # SEE: https://docs.python.org/2/library/logging.html#logrecord-attributes 6 8 [formatters] 7 9 keys=simple,detailed … … 9 11 [formatter_simple] 10 12 #format=%(asctime)s - %(name)s - %(levelname)s - %(message)s 13 #format=%(asctime)s - %(levelname)s : %(name)s:%(pathname)s:%(lineno)4d: %(message)s 11 14 format=%(asctime)s - %(levelname)s : %(name)s:%(lineno)4d: %(message)s 12 15 datefmt=%H:%M:%S … … 37 40 38 41 [loggers] 39 keys=root,sas gui,sascalc42 keys=root,saspr,sasgui,sascalc,sasmodels 40 43 41 44 [logger_root] 42 level= DEBUG45 level=INFO 43 46 formatter=default 44 47 handlers=console,log_file 48 49 [logger_sasmodels] 50 level=INFO 51 qualname=sas.models 52 handlers=console,log_file 53 propagate=0 54 55 [logger_saspr] 56 level=INFO 57 qualname=sas.pr 58 handlers=console,log_file 59 propagate=0 45 60 46 61 [logger_sasgui] … … 48 63 qualname=sas.sasgui 49 64 handlers=console,log_file 50 65 propagate=0 66 51 67 [logger_sascalc] 52 level= DEBUG68 level=INFO 53 69 qualname=sas.sascalc 54 70 handlers=console,log_file 71 propagate=0 55 72 -
sasview/sasview.py
r463e7ffc r64ca561 17 17 import traceback 18 18 19 20 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.ini')21 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=False)22 logging.captureWarnings(True)23 19 logger = logging.getLogger(__name__) 24 20 if not logger.root.handlers: 21 print "This should NOT appear in called from run.py: %s", logger.handlers 22 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.ini') 23 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=False) 24 logging.captureWarnings(True) 25 25 26 26 # Log the start of the session 27 logging.info(" --- SasView session started ---") 28 27 logger.info(" --- SasView session started ---") 29 28 # Log the python version 30 logg ing.info("Python: %s" % sys.version)29 logger.info("Python: %s" % sys.version) 31 30 32 31 # Allow the dynamic selection of wxPython via an environment variable, when devs … … 37 36 WX_ENV_VAR = "SASVIEW_WX_VERSION" 38 37 if WX_ENV_VAR in os.environ: 39 logg ing.info("You have set the %s environment variable to %s." % \38 logger.info("You have set the %s environment variable to %s." % \ 40 39 (WX_ENV_VAR, os.environ[WX_ENV_VAR])) 41 40 import wxversion 42 41 if wxversion.checkInstalled(os.environ[WX_ENV_VAR]): 43 logg ing.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR])42 logger.info("Version %s of wxPython is installed, so using that version." % os.environ[WX_ENV_VAR]) 44 43 wxversion.select(os.environ[WX_ENV_VAR]) 45 44 else: 46 logg ing.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR])45 logger.error("Version %s of wxPython is not installed, so using default version." % os.environ[WX_ENV_VAR]) 47 46 else: 48 logg ing.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR)47 logger.info("You have not set the %s environment variable, so using default version of wxPython." % WX_ENV_VAR) 49 48 50 49 import wx 51 50 52 51 try: 53 logg ing.info("Wx version: %s" % wx.__version__)52 logger.info("Wx version: %s" % wx.__version__) 54 53 except: 55 logg ing.error("Wx version: error reading version")54 logger.error("Wx version: error reading version") 56 55 57 56 import wxcruft … … 106 105 self.gui.add_perspective(fitting_plug) 107 106 except Exception: 108 logg ing.error("%s: could not find Fitting plug-in module"% APP_NAME)109 logg ing.error(traceback.format_exc())107 logger.error("%s: could not find Fitting plug-in module"% APP_NAME) 108 logger.error(traceback.format_exc()) 110 109 111 110 # P(r) perspective … … 115 114 self.gui.add_perspective(pr_plug) 116 115 except: 117 logg ing.error("%s: could not find P(r) plug-in module"% APP_NAME)118 logg ing.error(traceback.format_exc())116 logger.error("%s: could not find P(r) plug-in module"% APP_NAME) 117 logger.error(traceback.format_exc()) 119 118 120 119 #Invariant perspective … … 124 123 self.gui.add_perspective(invariant_plug) 125 124 except Exception as e : 126 logg ing.error("%s: could not find Invariant plug-in module"% \125 logger.error("%s: could not find Invariant plug-in module"% \ 127 126 APP_NAME) 128 logg ing.error(traceback.format_exc())127 logger.error(traceback.format_exc()) 129 128 130 129 # Corfunc perspective … … 134 133 self.gui.add_perspective(corfunc_plug) 135 134 except: 136 logg ing.error("Unable to load corfunc module")135 logger.error("Unable to load corfunc module") 137 136 138 137 #Calculator perspective … … 142 141 self.gui.add_perspective(calculator_plug) 143 142 except: 144 logg ing.error("%s: could not find Calculator plug-in module"% \143 logger.error("%s: could not find Calculator plug-in module"% \ 145 144 APP_NAME) 146 logg ing.error(traceback.format_exc())145 logger.error(traceback.format_exc()) 147 146 148 147 # File converter tool … … 152 151 self.gui.add_perspective(converter_plug) 153 152 except: 154 logg ing.error("%s: could not find File Converter plug-in module"% \153 logger.error("%s: could not find File Converter plug-in module"% \ 155 154 APP_NAME) 156 logg ing.error(traceback.format_exc())155 logger.error(traceback.format_exc()) 157 156 158 157 -
src/sas/sascalc/data_util/calcthread.py
r463e7ffc r64ca561 246 246 except Exception: 247 247 pass 248 import logging249 248 logger.error(traceback.format_exc()) 250 249 #print 'CalcThread exception', -
src/sas/sasgui/guiframe/config.py
r9c0f3c17 r64ca561 10 10 11 11 logger = logging.getLogger(__name__) 12 13 12 14 13 # Version of the application -
src/sas/sasgui/guiframe/gui_manager.py
r463e7ffc r64ca561 51 51 52 52 warnings.simplefilter("ignore") 53 54 53 55 54 def get_app_dir(): -
test/logging.ini
rc155a16 r64ca561 35 35 36 36 [loggers] 37 keys= root,sas37 keys=test,sas 38 38 39 [logger_ root]39 [logger_test] 40 40 level=DEBUG 41 41 formatter=default -
test/run_one.py
r463e7ffc r64ca561 9 9 10 10 import logging 11 import logging.config12 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.ini')13 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=False)14 11 logger = logging.getLogger(__name__) 12 if not logger.root.handlers: 13 import logging.config 14 LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.ini') 15 logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=False) 16 15 17 16 18 run_py = joinpath(dirname(dirname(abspath(__file__))), 'run.py')
Note: See TracChangeset
for help on using the changeset viewer.