Changes in run.py [05a9d29:64ca561] in sasview


Ignore:
File:
1 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     
Note: See TracChangeset for help on using the changeset viewer.