Changeset 64ca561 in sasview


Ignore:
Timestamp:
Apr 5, 2017 7:24:44 AM (8 years ago)
Author:
Ricardo Ferraz Leal <ricleal@…>
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
Message:

Log not repeated any longer

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • run.py

    r05a9d29 r64ca561  
    1717import sys 
    1818import imp 
     19import logging 
     20import logging.config 
     21 
    1922from contextlib import contextmanager 
    2023from os.path import abspath, dirname, join as joinpath 
    2124 
    22 class TeeStream: 
    23     def __init__(self, filename): 
    24         self.logfile = open(filename, 'a') 
    25         self.console = sys.stderr 
    26     def write(self, buf): 
    27         self.logfile.write(buf) 
    28         self.console.write(buf) 
    2925 
    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) 
     26LOGGER_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'sasview/logging.ini') 
     27logging.config.fileConfig(LOGGER_CONFIG_FILE, disable_existing_loggers=True) 
     28logger = logging.getLogger(__name__) 
    3629 
     30def 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         
    3739def addpath(path): 
    3840    """ 
     
    152154 
    153155if __name__ == "__main__": 
     156    update_all_logs_to_debug(logger) 
    154157    prepare() 
    155     tee_logging() 
    156158    from sas.sasview.sasview import run 
    157159    run() 
     160     
  • sasview/logging.ini

    r9c0f3c17 r64ca561  
    33################################### LOGGING ################################### 
    44############################################################################### 
     5# Main logger for SASView 
    56 
     7# SEE: https://docs.python.org/2/library/logging.html#logrecord-attributes 
    68[formatters] 
    79keys=simple,detailed 
     
    911[formatter_simple] 
    1012#format=%(asctime)s - %(name)s - %(levelname)s - %(message)s 
     13#format=%(asctime)s - %(levelname)s : %(name)s:%(pathname)s:%(lineno)4d: %(message)s 
    1114format=%(asctime)s - %(levelname)s : %(name)s:%(lineno)4d: %(message)s 
    1215datefmt=%H:%M:%S 
     
    3740 
    3841[loggers] 
    39 keys=root,sasgui,sascalc 
     42keys=root,saspr,sasgui,sascalc,sasmodels 
    4043 
    4144[logger_root] 
    42 level=DEBUG 
     45level=INFO 
    4346formatter=default 
    4447handlers=console,log_file 
     48 
     49[logger_sasmodels] 
     50level=INFO 
     51qualname=sas.models 
     52handlers=console,log_file 
     53propagate=0 
     54 
     55[logger_saspr] 
     56level=INFO 
     57qualname=sas.pr 
     58handlers=console,log_file 
     59propagate=0 
    4560 
    4661[logger_sasgui] 
     
    4863qualname=sas.sasgui 
    4964handlers=console,log_file 
    50   
     65propagate=0 
     66 
    5167[logger_sascalc] 
    52 level=DEBUG 
     68level=INFO 
    5369qualname=sas.sascalc 
    5470handlers=console,log_file 
     71propagate=0 
    5572 
  • sasview/sasview.py

    r463e7ffc r64ca561  
    1717import traceback 
    1818 
    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) 
    2319logger = logging.getLogger(__name__) 
    24  
     20if 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) 
    2525 
    2626# Log the start of the session 
    27 logging.info(" --- SasView session started ---") 
    28  
     27logger.info(" --- SasView session started ---") 
    2928# Log the python version 
    30 logging.info("Python: %s" % sys.version) 
     29logger.info("Python: %s" % sys.version) 
    3130 
    3231# Allow the dynamic selection of wxPython via an environment variable, when devs 
     
    3736WX_ENV_VAR = "SASVIEW_WX_VERSION" 
    3837if WX_ENV_VAR in os.environ: 
    39     logging.info("You have set the %s environment variable to %s." % \ 
     38    logger.info("You have set the %s environment variable to %s." % \ 
    4039                 (WX_ENV_VAR, os.environ[WX_ENV_VAR])) 
    4140    import wxversion 
    4241    if wxversion.checkInstalled(os.environ[WX_ENV_VAR]): 
    43         logging.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]) 
    4443        wxversion.select(os.environ[WX_ENV_VAR]) 
    4544    else: 
    46         logging.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]) 
    4746else: 
    48     logging.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) 
    4948 
    5049import wx 
    5150 
    5251try: 
    53     logging.info("Wx version: %s" % wx.__version__) 
     52    logger.info("Wx version: %s" % wx.__version__) 
    5453except: 
    55     logging.error("Wx version: error reading version") 
     54    logger.error("Wx version: error reading version") 
    5655 
    5756import wxcruft 
     
    106105            self.gui.add_perspective(fitting_plug) 
    107106        except Exception: 
    108             logging.error("%s: could not find Fitting plug-in module"% APP_NAME) 
    109             logging.error(traceback.format_exc()) 
     107            logger.error("%s: could not find Fitting plug-in module"% APP_NAME) 
     108            logger.error(traceback.format_exc()) 
    110109 
    111110        # P(r) perspective 
     
    115114            self.gui.add_perspective(pr_plug) 
    116115        except: 
    117             logging.error("%s: could not find P(r) plug-in module"% APP_NAME) 
    118             logging.error(traceback.format_exc()) 
     116            logger.error("%s: could not find P(r) plug-in module"% APP_NAME) 
     117            logger.error(traceback.format_exc()) 
    119118 
    120119        #Invariant perspective 
     
    124123            self.gui.add_perspective(invariant_plug) 
    125124        except Exception as e : 
    126             logging.error("%s: could not find Invariant plug-in module"% \ 
     125            logger.error("%s: could not find Invariant plug-in module"% \ 
    127126                          APP_NAME) 
    128             logging.error(traceback.format_exc()) 
     127            logger.error(traceback.format_exc()) 
    129128 
    130129        # Corfunc perspective 
     
    134133            self.gui.add_perspective(corfunc_plug) 
    135134        except: 
    136             logging.error("Unable to load corfunc module") 
     135            logger.error("Unable to load corfunc module") 
    137136 
    138137        #Calculator perspective 
     
    142141            self.gui.add_perspective(calculator_plug) 
    143142        except: 
    144             logging.error("%s: could not find Calculator plug-in module"% \ 
     143            logger.error("%s: could not find Calculator plug-in module"% \ 
    145144                                                        APP_NAME) 
    146             logging.error(traceback.format_exc()) 
     145            logger.error(traceback.format_exc()) 
    147146 
    148147        # File converter tool 
     
    152151            self.gui.add_perspective(converter_plug) 
    153152        except: 
    154             logging.error("%s: could not find File Converter plug-in module"% \ 
     153            logger.error("%s: could not find File Converter plug-in module"% \ 
    155154                                                        APP_NAME) 
    156             logging.error(traceback.format_exc()) 
     155            logger.error(traceback.format_exc()) 
    157156 
    158157 
  • src/sas/sascalc/data_util/calcthread.py

    r463e7ffc r64ca561  
    246246            except Exception: 
    247247                pass 
    248         import logging 
    249248        logger.error(traceback.format_exc()) 
    250249        #print 'CalcThread exception', 
  • src/sas/sasgui/guiframe/config.py

    r9c0f3c17 r64ca561  
    1010 
    1111logger = logging.getLogger(__name__) 
    12  
    1312 
    1413# Version of the application 
  • src/sas/sasgui/guiframe/gui_manager.py

    r463e7ffc r64ca561  
    5151 
    5252warnings.simplefilter("ignore") 
    53  
    5453 
    5554def get_app_dir(): 
  • test/logging.ini

    rc155a16 r64ca561  
    3535 
    3636[loggers] 
    37 keys=root,sas 
     37keys=test,sas 
    3838 
    39 [logger_root] 
     39[logger_test] 
    4040level=DEBUG 
    4141formatter=default 
  • test/run_one.py

    r463e7ffc r64ca561  
    99 
    1010import logging 
    11 import logging.config 
    12 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) 
    1411logger = logging.getLogger(__name__) 
     12if 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 
    1517 
    1618run_py = joinpath(dirname(dirname(abspath(__file__))), 'run.py') 
Note: See TracChangeset for help on using the changeset viewer.