Changeset 5dba493 in sasview
- Timestamp:
- Jul 11, 2018 8:47:52 AM (6 years ago)
- Children:
- 158a0c7
- Parents:
- 4dd5766
- Location:
- src/sas
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/logger_config.py
rcee5c78 r5dba493 8 8 import pkg_resources 9 9 10 import sas.qtgui.Utilities.LocalConfig as LocalConfig 10 11 11 12 ''' … … 29 30 logging.captureWarnings(True) 30 31 logger = logging.getLogger(self.name) 32 33 # use this as a final override if the need arises 34 logging.disable(LocalConfig.DISABLE_LOGGING) 35 31 36 return logger 32 37 … … 38 43 self._update_all_logs_to_debug(logger) 39 44 logging.captureWarnings(True) 45 46 # use this as a final override if the need arises 47 logging.disable(LocalConfig.DISABLE_LOGGING) 48 40 49 return logger 41 50 … … 49 58 ''' 50 59 for handler in logger.handlers or logger.parent.handlers: 51 #handler.setLevel(logging.DEBUG) 52 handler.setLevel(logging.WARNING) 60 handler.setLevel(logging.DEBUG) 53 61 for name, _ in logging.Logger.manager.loggerDict.items(): 54 #logging.getLogger(name).setLevel(logging.DEBUG) 55 logging.getLogger(name).setLevel(logging.WARNING) 62 logging.getLogger(name).setLevel(logging.DEBUG) 56 63 57 64 def _find_config_file(self, filename="logging.ini"): -
src/sas/logging.ini
r7c105e8 r5dba493 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/MainWindow.py
ra3221b6 r5dba493 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 r5dba493 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 r5dba493 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 r5dba493 7 7 8 8 class XStream(QObject): 9 """ 10 Imitates, loosely, an `io.TextIOWrapper` class in order to intercept 11 messages going to stdout and stderr. 12 13 To intercept messages to stdout, use: 14 15 .. code-block:: python 16 XStream.stdout().messageWritten.mySignalHandler() 17 18 All messages to stdout will now also be emitted to your handler. Use 19 `XStream.stderr()` in the same way to intercept stderr messages. 20 21 An additional function, `XStream.write_log()`, emits a message only to the 22 messageWritten signal, and not the stdout or stderr streams. It is intended 23 for separation of log handling between console and Qt, as reflected in the 24 name. 25 """ 9 26 _stdout = None 10 27 _stderr = None 11 28 messageWritten = pyqtSignal(str) 29 30 _real_stream = None 12 31 13 32 def flush(self): … … 18 37 19 38 def write(self, msg): 39 """ 40 'msg' is emitted in the messageWritten signal, and is also written to 41 the original stream. This means stdout/stderr messages have been 42 redirected to a custom location (e.g. in-widget), but also reach 43 console output. 44 45 :param msg: message to write 46 :return: None 47 """ 48 if(not self.signalsBlocked()): 49 self.messageWritten.emit(str(msg)) 50 self._real_stream.write(msg) 51 52 def write_log(self, msg): 53 """ 54 'msg' is only emitted in the messageWritten signal, not in the original 55 stdout/stderr stream, for the purposes of logging. Use in, e.g. a 56 custom logging handler's emit() function. 57 58 :param msg: message to write 59 :return: None 60 """ 20 61 if(not self.signalsBlocked()): 21 62 self.messageWritten.emit(str(msg)) … … 23 64 @staticmethod 24 65 def stdout(): 66 """ 67 Creates imitation of sys.stdout. 68 :return: An XStream instance that interfaces exactly like sys.stdout, 69 but, has redirection capabilities through the 70 messageWritten(str) signal. 71 """ 25 72 if(not XStream._stdout): 26 73 XStream._stdout = XStream() 74 XStream._stdout._real_stream = sys.stdout 27 75 sys.stdout = XStream._stdout 28 76 return XStream._stdout … … 30 78 @staticmethod 31 79 def stderr(): 80 """ 81 Creates imitation of sys.stderr. 82 :return: An XStream instance that interfaces exactly like sys.stderr, 83 but, has redirection capabilities through the 84 messageWritten(str) signal. 85 """ 32 86 if(not XStream._stderr): 33 87 XStream._stderr = XStream() 88 XStream._stderr._real_stream = sys.stderr 34 89 sys.stderr = XStream._stderr 35 90 return XStream._stderr 36 91 92 37 93 class QtHandler(logging.Handler): 38 94 """ 39 Version of logging handler 40 "emitting" the message to custom stdout() 95 Version of logging handler "emitting" the message to custom stdout() 41 96 """ 42 97 def __init__(self): … … 46 101 record = self.format(record) 47 102 if record: 48 XStream.stdout().write ('%s\n'%record)103 XStream.stdout().write_log('%s\n'%record) 49 104 50 105 … … 52 107 logger = logging.getLogger() 53 108 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 109 # Add the qt-signal logger 60 110 handler = QtHandler() 61 handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) 111 handler.setFormatter(logging.Formatter( 112 fmt="%(asctime)s - %(levelname)s: %(message)s", 113 datefmt="%H:%M:%S" 114 )) 62 115 logger.addHandler(handler)
Note: See TracChangeset
for help on using the changeset viewer.