prevented the console window to appear and diaply messages that are irrelevant to users.
To do this, I turned log messages into debug messages. While doing so, I also added an IJLogger that is able to log messages on imagej console, in case we need it in the future
This commit is contained in:
parent
dbc22ea3b1
commit
442645d710
|
@ -29,6 +29,7 @@ from lipase.imagej.ijimageengine import IJImageEngine
|
|||
from lipase.telemos import WhiteEstimator
|
||||
from lipase.catalog import ImageCatalog
|
||||
from lipase.imagej import open_sequence_in_imagej
|
||||
from lipase import logger
|
||||
|
||||
from ij import IJ
|
||||
from ij.gui import GenericDialog, DialogListener
|
||||
|
@ -52,12 +53,12 @@ class SequenceChoiceListener(ItemListener):
|
|||
self.catalog = catalog
|
||||
|
||||
def itemStateChanged(self, event):
|
||||
IJ.log("SequenceChoiceListener : Something was changed (event = %s)" % event)
|
||||
logger.debug("SequenceChoiceListener : Something was changed (event = %s)" % event)
|
||||
# SequenceChoiceListener : Something was changed (event = java.awt.event.ItemEvent[ITEM_STATE_CHANGED,item=res_soleil2018/DARK/DARK_40X_60min_1 im pae min_1/Pos0,stateChange=SELECTED] on choice3)
|
||||
IJ.log("SequenceChoiceListener : event's attributes : %s" % str(dir(event)))
|
||||
logger.debug("SequenceChoiceListener : event's attributes : %s" % str(dir(event)))
|
||||
# SequenceChoiceListener : event's attributes : ['ACTION_EVENT_MASK', 'ADJUSTMENT_EVENT_MASK', 'COMPONENT_EVENT_MASK', 'CONTAINER_EVENT_MASK', 'DESELECTED', 'FOCUS_EVENT_MASK', 'HIERARCHY_BOUNDS_EVENT_MASK', 'HIERARCHY_EVENT_MASK', 'ID', 'INPUT_METHOD_EVENT_MASK', 'INVOCATION_EVENT_MASK', 'ITEM_EVENT_MASK', 'ITEM_FIRST', 'ITEM_LAST', 'ITEM_STATE_CHANGED', 'KEY_EVENT_MASK', 'MOUSE_EVENT_MASK', 'MOUSE_MOTION_EVENT_MASK', 'MOUSE_WHEEL_EVENT_MASK', 'PAINT_EVENT_MASK', 'RESERVED_ID_MAX', 'SELECTED', 'TEXT_EVENT_MASK', 'WINDOW_EVENT_MASK', 'WINDOW_FOCUS_EVENT_MASK', 'WINDOW_STATE_EVENT_MASK', '__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__ensure_finalizer__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'equals', 'getClass', 'getID', 'getItem', 'getItemSelectable', 'getSource', 'getStateChange', 'hashCode', 'item', 'itemSelectable', 'notify', 'notifyAll', 'paramString', 'setSource', 'source', 'stateChange', 'toString', 'wait']
|
||||
IJ.log("SequenceChoiceListener : event.item : %s" % str(event.item))
|
||||
IJ.log("SequenceChoiceListener : type(event.item) : %s" % str(type(event.item)))
|
||||
logger.debug("SequenceChoiceListener : event.item : %s" % str(event.item))
|
||||
logger.debug("SequenceChoiceListener : type(event.item) : %s" % str(type(event.item)))
|
||||
selected_sequence_id = event.item
|
||||
selected_sequence = self.catalog.sequences[selected_sequence_id]
|
||||
channel_ids = selected_sequence.get_channel_names()
|
||||
|
@ -79,7 +80,7 @@ def ask_for_sequence(catalog):
|
|||
channel_ids = catalog.sequences[default_sequence_id].get_channel_names()
|
||||
gd.addChoice('channel', channel_ids, channel_ids[0])
|
||||
choices = gd.getChoices()
|
||||
IJ.log("choices = %s" % choices)
|
||||
logger.debug("choices = %s" % choices)
|
||||
sequence_choice = choices[0]
|
||||
channel_choice = choices[1]
|
||||
sequence_choice.addItemListener(SequenceChoiceListener(channel_choice, catalog))
|
||||
|
@ -107,7 +108,7 @@ def run_script():
|
|||
return
|
||||
sequence = user_selection['sequence']
|
||||
channel_id = str(user_selection['channel_id'])
|
||||
IJ.log("channel_id = %s (type = %s)" % (channel_id, str(type(channel_id))))
|
||||
logger.debug("channel_id = %s (type = %s)" % (channel_id, str(type(channel_id))))
|
||||
if channel_id == 'all':
|
||||
sequence_as_stack = open_sequence_in_imagej(sequence)
|
||||
else:
|
||||
|
|
|
@ -3,16 +3,42 @@ import logging
|
|||
import logging.handlers
|
||||
import logging
|
||||
import os
|
||||
from ij import IJ
|
||||
|
||||
|
||||
class IJLogger():
|
||||
'''a logger with the same interface as logging.getLogger() but which uses imagej's log() mechanism
|
||||
|
||||
todo: apparently, IJ.log() logs an INFO message by default. I don't know how to log messages with other severities (WARNING, ERRORS). So, instead, I prepend the severity as a string to the message, which is not great...
|
||||
'''
|
||||
def debug(self, message):
|
||||
IJ.log('DEBUG : %s' % message)
|
||||
|
||||
def info(self, message):
|
||||
IJ.log('INFO : %s' % message)
|
||||
|
||||
def warn(self, message):
|
||||
IJ.log('WARN : %s' % message)
|
||||
|
||||
def error(self, message):
|
||||
IJ.log('ERROR : %s' % message)
|
||||
|
||||
|
||||
|
||||
def create_logger():
|
||||
global logger
|
||||
# logging.basicConfig( stream=sys.stderr )
|
||||
handler = logging.FileHandler(os.environ.get("LOGFILE", "/tmp/lipase.log"))
|
||||
formatter = logging.Formatter(logging.BASIC_FORMAT)
|
||||
handler.setFormatter(formatter)
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel( logging.DEBUG )
|
||||
logger.addHandler(handler)
|
||||
logger_type = 'std_python_logger' # 'std_python_logger' or 'ij_logger'
|
||||
if logger_type == 'std_python_logger':
|
||||
# logging.basicConfig( stream=sys.stderr )
|
||||
handler = logging.FileHandler(os.environ.get("LOGFILE", "/tmp/lipase.log"))
|
||||
formatter = logging.Formatter(logging.BASIC_FORMAT)
|
||||
handler.setFormatter(formatter)
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel( logging.DEBUG )
|
||||
logger.addHandler(handler)
|
||||
elif logger_type == 'std_python_logger':
|
||||
logger = IJLogger()
|
||||
else:
|
||||
assert False
|
||||
return logger
|
||||
|
||||
logger = create_logger()
|
||||
|
|
Loading…
Reference in New Issue