Changes in / [200ce9c:a2b74bb] in sasview
- Location:
- src/sas
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/logger_config.py
re4335ae rcee5c78 7 7 8 8 import pkg_resources 9 9 10 10 11 ''' … … 28 29 logging.captureWarnings(True) 29 30 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 41 40 return logger 42 41 … … 50 49 ''' 51 50 for handler in logger.handlers or logger.parent.handlers: 52 handler.setLevel(logging.DEBUG) 51 #handler.setLevel(logging.DEBUG) 52 handler.setLevel(logging.WARNING) 53 53 for name, _ in logging.Logger.manager.loggerDict.items(): 54 logging.getLogger(name).setLevel(logging.DEBUG) 54 #logging.getLogger(name).setLevel(logging.DEBUG) 55 logging.getLogger(name).setLevel(logging.WARNING) 55 56 56 57 def _find_config_file(self, filename="logging.ini"): -
src/sas/logging.ini
re4335ae r7c105e8 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 15 format=%(asctime)s - %(levelname)s: %(message)s 14 format=%(asctime)s - %(levelname)s : %(name)s:%(lineno)4d: %(message)s 16 15 datefmt=%H:%M:%S 17 16 -
src/sas/qtgui/MainWindow/GuiManager.py
re4335ae rf0a8f74 13 13 # General SAS imports 14 14 from sas.qtgui.Utilities.ConnectionProxy import ConnectionProxy 15 from sas.qtgui.Utilities.SasviewLogger import setup_qt_logging15 from sas.qtgui.Utilities.SasviewLogger import XStream 16 16 17 17 import sas.qtgui.Utilities.LocalConfig as LocalConfig … … 86 86 87 87 # Fork off logging messages to the Log Window 88 handler = setup_qt_logging()89 handler.messageWritten.connect(self.appendLog)88 XStream.stdout().messageWritten.connect(self.listWidget.insertPlainText) 89 XStream.stderr().messageWritten.connect(self.listWidget.insertPlainText) 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 this274 instead of listWidget.insertPlainText() to facilitate auto-scrolling"""275 self.listWidget.append(msg.strip())276 271 277 272 def createGuiData(self, item, p_file=None): -
src/sas/qtgui/MainWindow/MainWindow.py
re4335ae ra3221b6 10 10 from sas.qtgui.UI import main_resources_rc 11 11 from .UI.MainWindowUI import Ui_MainWindow 12 13 # Initialize logging 14 import sas.qtgui.Utilities.SasviewLogger 12 15 13 16 class MainSasViewWindow(QMainWindow, Ui_MainWindow): -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
re4335ae re20870bc 106 106 # Globals 107 107 self.initializeGlobals() 108 109 # Set up desired logging level 110 logging.disable(LocalConfig.DISABLE_LOGGING) 108 111 109 112 # data index for the batch set -
src/sas/qtgui/Utilities/LocalConfig.py
re4335ae ra0ed202 136 136 USING_TWISTED = True 137 137 138 # Logging levels to disable, if any 139 DISABLE_LOGGING = logging.DEBUG 140 138 141 # Time out for updating sasview 139 142 UPDATE_TIMEOUT = 2 140 143 141 144 # Logging levels to disable, if any 142 DISABLE_LOGGING = logging. NOTSET145 DISABLE_LOGGING = logging.DEBUG 143 146 144 147 def printEVT(message): -
src/sas/qtgui/Utilities/SasviewLogger.py
re4335ae r4992ff2 6 6 7 7 8 class QtHandler(QObject, logging.Handler): 9 """ 10 Version of logging handler "emitting" the message to custom stdout() 11 """ 8 class XStream(QObject): 9 _stdout = None 10 _stderr = None 12 11 messageWritten = pyqtSignal(str) 13 12 13 def flush(self): 14 pass 15 16 def fileno(self): 17 return -1 18 19 def write(self, msg): 20 if(not self.signalsBlocked()): 21 self.messageWritten.emit(str(msg)) 22 23 @staticmethod 24 def stdout(): 25 if(not XStream._stdout): 26 XStream._stdout = XStream() 27 sys.stdout = XStream._stdout 28 return XStream._stdout 29 30 @staticmethod 31 def stderr(): 32 if(not XStream._stderr): 33 XStream._stderr = XStream() 34 sys.stderr = XStream._stderr 35 return XStream._stderr 36 37 class QtHandler(logging.Handler): 38 """ 39 Version of logging handler 40 "emitting" the message to custom stdout() 41 """ 14 42 def __init__(self): 15 QObject.__init__(self)16 43 logging.Handler.__init__(self) 17 44 … … 19 46 record = self.format(record) 20 47 if record: 21 self.messageWritten.emit('%s\n'%record)48 XStream.stdout().write('%s\n'%record) 22 49 23 50 24 def setup_qt_logging(): 25 # Define the default logger 26 logger = logging.getLogger() 51 # Define the default logger 52 logger = logging.getLogger() 27 53 28 # Add the qt-signal logger29 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 54 # Add the file handler 55 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) -
src/sas/qtgui/Utilities/UnitTesting/SasviewLoggerTest.py
re4335ae r53c771e 11 11 12 12 # Local 13 from sas.qtgui.Utilities.SasviewLogger import XStream 13 14 from sas.qtgui.Utilities.SasviewLogger import QtHandler 14 15 … … 22 23 """ 23 24 self.logger = logging.getLogger(__name__) 24 self.handler = QtHandler()25 self.handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))26 self.logger.addHandler( self.handler)25 handler = QtHandler() 26 handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) 27 self.logger.addHandler(handler) 27 28 self.logger.setLevel(logging.DEBUG) 28 29 … … 34 35 Test redirection of all levels of logging 35 36 """ 36 # Attach the listener 37 self.handler.messageWritten.connect(self.outHandlerGui.insertPlainText) 37 # Attach the listeners 38 XStream.stderr().messageWritten.connect( self.outHandlerGui.insertPlainText ) 39 XStream.stdout().messageWritten.connect( self.outHandlerGui.insertPlainText ) 38 40 39 41 # Send the signals … … 42 44 self.logger.warning('warning message') 43 45 self.logger.error('error message') 46 sys.stdout.write('with stdout') 47 sys.stderr.write('with stderr') 44 48 45 49 out=self.outHandlerGui.toPlainText() … … 50 54 self.assertIn('WARNING: warning message', out) 51 55 self.assertIn('ERROR: error message', out) 56 self.assertIn('with stdout', out) 57 self.assertIn('with stderr', out) 52 58 53 59 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.