Changeset 517f3d4 in sasview for sasview/sasview.py


Ignore:
Timestamp:
Mar 2, 2015 9:36:57 AM (9 years ago)
Author:
Doucet, Mathieu <doucetm@…>
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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
f89fa84
Parents:
18d58a6e
Message:

Write stderr to sasview.log

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasview/sasview.py

    rcaf3baa6 r517f3d4  
    1010################################################################################ 
    1111import os 
     12import sys 
    1213import logging 
    1314from shutil import copy 
     
    1718                                          'sasview.log')) 
    1819 
    19 # Allow the dynamic selection of wxPython via an evironment variable, when devs 
     20class StreamToLogger(object): 
     21    """ 
     22        File-like stream object that redirects writes to a logger instance. 
     23    """ 
     24    def __init__(self, logger, log_level=logging.INFO): 
     25        self.logger = logger 
     26        self.log_level = log_level 
     27        self.linebuf = '' 
     28  
     29    def write(self, buf): 
     30        # Write the message to stdout so we can see it when running interactively 
     31        sys.stdout.write(buf) 
     32        for line in buf.rstrip().splitlines(): 
     33            self.logger.log(self.log_level, line.rstrip()) 
     34 
     35stderr_logger = logging.getLogger('STDERR') 
     36sl = StreamToLogger(stderr_logger, logging.ERROR) 
     37sys.stderr = sl 
     38 
     39# Log the python version 
     40logging.info("Python: %s" % sys.version) 
     41 
     42# Allow the dynamic selection of wxPython via an environment variable, when devs 
    2043# who have multiple versions of the module installed want to pick between them. 
    2144# This variable does not have to be set of course, and through normal usage will 
     
    3558 
    3659import wx 
    37 import sys 
     60try: 
     61    logging.info("Wx version: %s" % wx.__version__) 
     62except: 
     63    logging.error("Wx version: error reading version") 
     64     
    3865# The below will make sure that sasview application uses the matplotlib font  
    3966# bundled with sasview.  
Note: See TracChangeset for help on using the changeset viewer.