Changeset e4335ae in sasview
- Timestamp:
- Jul 19, 2018 6:12:03 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- c0de493
- Parents:
- 02e7d3a
- git-author:
- Torin Cooper-Bennun <40573959+tcbennun@…> (07/19/18 06:12:03)
- git-committer:
- Piotr Rozyczko <piotr.rozyczko@…> (07/19/18 06:12:03)
- Location:
- src/sas
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/logger_config.py
rcee5c78 re4335ae 7 7 8 8 import pkg_resources 9 10 9 11 10 ''' … … 29 28 logging.captureWarnings(True) 30 29 logger = logging.getLogger(self.name) 30 31 31 return logger 32 32 … … 38 38 self._update_all_logs_to_debug(logger) 39 39 logging.captureWarnings(True) 40 40 41 return logger 41 42 … … 49 50 ''' 50 51 for handler in logger.handlers or logger.parent.handlers: 51 #handler.setLevel(logging.DEBUG) 52 handler.setLevel(logging.WARNING) 52 handler.setLevel(logging.DEBUG) 53 53 for name, _ in logging.Logger.manager.loggerDict.items(): 54 #logging.getLogger(name).setLevel(logging.DEBUG) 55 logging.getLogger(name).setLevel(logging.WARNING) 54 logging.getLogger(name).setLevel(logging.DEBUG) 56 55 57 56 def _find_config_file(self, filename="logging.ini"): -
src/sas/logging.ini
r7c105e8 re4335ae 12 12 #format=%(asctime)s - %(name)s - %(levelname)s - %(message)s 13 13 #format=%(asctime)s - %(levelname)s : %(name)s:%(pathname)s:%(lineno)4d: %(message)s 14 format=%(asctime)s - %(levelname)s : %(name)s:%(lineno)4d: %(message)s 14 #format=%(asctime)s - %(levelname)s : %(name)s:%(lineno)4d: %(message)s 15 format=%(asctime)s - %(levelname)s: %(message)s 15 16 datefmt=%H:%M:%S 16 17 -
src/sas/qtgui/MainWindow/GuiManager.py
rf0a8f74 re4335ae 13 13 # General SAS imports 14 14 from sas.qtgui.Utilities.ConnectionProxy import ConnectionProxy 15 from sas.qtgui.Utilities.SasviewLogger import XStream15 from sas.qtgui.Utilities.SasviewLogger import setup_qt_logging 16 16 17 17 import sas.qtgui.Utilities.LocalConfig as LocalConfig … … 86 86 87 87 # Fork off logging messages to the Log Window 88 XStream.stdout().messageWritten.connect(self.listWidget.insertPlainText)89 XStream.stderr().messageWritten.connect(self.listWidget.insertPlainText)88 handler = setup_qt_logging() 89 handler.messageWritten.connect(self.appendLog) 90 90 91 91 # Log the start of the session … … 269 269 """ 270 270 self.statusLabel.setText(text) 271 272 def appendLog(self, msg): 273 """Appends a message to the list widget in the Log Explorer. Use this 274 instead of listWidget.insertPlainText() to facilitate auto-scrolling""" 275 self.listWidget.append(msg.strip()) 271 276 272 277 def createGuiData(self, item, p_file=None): -
src/sas/qtgui/MainWindow/MainWindow.py
ra3221b6 re4335ae 10 10 from sas.qtgui.UI import main_resources_rc 11 11 from .UI.MainWindowUI import Ui_MainWindow 12 13 # Initialize logging14 import sas.qtgui.Utilities.SasviewLogger15 12 16 13 class MainSasViewWindow(QMainWindow, Ui_MainWindow): -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
re20870bc re4335ae 106 106 # Globals 107 107 self.initializeGlobals() 108 109 # Set up desired logging level110 logging.disable(LocalConfig.DISABLE_LOGGING)111 108 112 109 # data index for the batch set -
src/sas/qtgui/Utilities/LocalConfig.py
ra0ed202 re4335ae 136 136 USING_TWISTED = True 137 137 138 # Logging levels to disable, if any139 DISABLE_LOGGING = logging.DEBUG140 141 138 # Time out for updating sasview 142 139 UPDATE_TIMEOUT = 2 143 140 144 141 # Logging levels to disable, if any 145 DISABLE_LOGGING = logging. DEBUG142 DISABLE_LOGGING = logging.NOTSET 146 143 147 144 def printEVT(message): -
src/sas/qtgui/Utilities/SasviewLogger.py
r4992ff2 re4335ae 6 6 7 7 8 class XStream(QObject): 9 _stdout = None 10 _stderr = None 8 class QtHandler(QObject, logging.Handler): 9 """ 10 Version of logging handler "emitting" the message to custom stdout() 11 """ 11 12 messageWritten = pyqtSignal(str) 12 13 13 def flush(self):14 pass15 16 def fileno(self):17 return -118 19 def write(self, msg):20 if(not self.signalsBlocked()):21 self.messageWritten.emit(str(msg))22 23 @staticmethod24 def stdout():25 if(not XStream._stdout):26 XStream._stdout = XStream()27 sys.stdout = XStream._stdout28 return XStream._stdout29 30 @staticmethod31 def stderr():32 if(not XStream._stderr):33 XStream._stderr = XStream()34 sys.stderr = XStream._stderr35 return XStream._stderr36 37 class QtHandler(logging.Handler):38 """39 Version of logging handler40 "emitting" the message to custom stdout()41 """42 14 def __init__(self): 15 QObject.__init__(self) 43 16 logging.Handler.__init__(self) 44 17 … … 46 19 record = self.format(record) 47 20 if record: 48 XStream.stdout().write('%s\n'%record)21 self.messageWritten.emit('%s\n'%record) 49 22 50 23 51 # Define the default logger 52 logger = logging.getLogger() 24 def setup_qt_logging(): 25 # Define the default logger 26 logger = logging.getLogger() 53 27 54 # Add the file handler55 logging.basicConfig(level=logging.INFO, 56 format='%(asctime)s %(levelname)s %(message)s',57 filename=os.path.join(os.path.expanduser("~"),58 'sasview.log'))59 # Add the qt-signal logger 60 handler = QtHandler()61 handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) 62 logger.addHandler(handler) 28 # Add the qt-signal logger 29 handler = QtHandler() 30 handler.setFormatter(logging.Formatter( 31 fmt="%(asctime)s - %(levelname)s: %(message)s", 32 datefmt="%H:%M:%S" 33 )) 34 logger.addHandler(handler) 35 36 return handler -
src/sas/qtgui/Utilities/UnitTesting/SasviewLoggerTest.py
r53c771e re4335ae 11 11 12 12 # Local 13 from sas.qtgui.Utilities.SasviewLogger import XStream14 13 from sas.qtgui.Utilities.SasviewLogger import QtHandler 15 14 … … 23 22 """ 24 23 self.logger = logging.getLogger(__name__) 25 handler = QtHandler()26 handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))27 self.logger.addHandler( handler)24 self.handler = QtHandler() 25 self.handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) 26 self.logger.addHandler(self.handler) 28 27 self.logger.setLevel(logging.DEBUG) 29 28 … … 35 34 Test redirection of all levels of logging 36 35 """ 37 # Attach the listeners 38 XStream.stderr().messageWritten.connect( self.outHandlerGui.insertPlainText ) 39 XStream.stdout().messageWritten.connect( self.outHandlerGui.insertPlainText ) 36 # Attach the listener 37 self.handler.messageWritten.connect(self.outHandlerGui.insertPlainText) 40 38 41 39 # Send the signals … … 44 42 self.logger.warning('warning message') 45 43 self.logger.error('error message') 46 sys.stdout.write('with stdout')47 sys.stderr.write('with stderr')48 44 49 45 out=self.outHandlerGui.toPlainText() … … 54 50 self.assertIn('WARNING: warning message', out) 55 51 self.assertIn('ERROR: error message', out) 56 self.assertIn('with stdout', out)57 self.assertIn('with stderr', out)58 52 59 53 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.