Пример #1
0
 def add_log(self):
     # Temporarily (for the duration of the 'with' block) set the
     # log level and context.
     # these are done by the IMP_OBJECT_LOG macro in C++
     with IMP.SetLogState(self.get_log_level()):
         with IMP.CreateLogContext(self.get_name() + "::add_log"):
             self.set_was_used(True)
             IMP.add_to_log(IMP.VERBOSE,
                            "A verbose message in the object\n")
Пример #2
0
 def test_log_targets(self):
     """Test log targets"""
     log_level = IMP.get_log_level()
     # Make sure we are not logging at level MEMORY, since that will add
     # extra logs (for ref/unref) and cause assertions to fail
     IMP.set_log_level(IMP.VERBOSE)
     s= StringIO()
     t=IMP.SetLogTarget(s)
     IMP.add_to_log("Hey there\n")
     IMP.add_to_log("Big guy")
     del t
     self.assertEqual(s.getvalue(), "Hey there\nBig guy")
     del s
     IMP.add_to_log("what's up")
     s= StringIO()
     t= IMP.SetLogTarget(s)
     IMP.add_to_log("Hey there\n")
     del s
     IMP.add_to_log("Big guy")
     IMP.set_log_level(log_level)
Пример #3
0
 def do_before_evaluate(self):
     IMP.add_to_log(
         IMP.TERSE,
         "Updating dummy " + self.get_name() + "\n")
     self.updated = True
Пример #4
0
class DummyObject(IMP.Object):

    def __init__(self):
        IMP.Object.__init__(self, "DummyObject%1%")

    def add_log(self):
        # Temporarily (for the duration of the 'with' block) set the
        # log level and context.
        # these are done by the IMP_OBJECT_LOG macro in C++
        with IMP.SetLogState(self.get_log_level()):
            with IMP.CreateLogContext(self.get_name() + "::add_log"):
                self.set_was_used(True)
                IMP.add_to_log(IMP.VERBOSE,
                               "A verbose message in the object\n")

# we can set the log level for all of IMP
IMP.set_log_level(IMP.TERSE)

# we can tell it to print the time each event occurs
IMP.set_log_timer(True)

# we can create a log context (valid for the duration of the 'with' block)
with IMP.CreateLogContext("my context"):

    # we can print a message
    IMP.add_to_log(IMP.TERSE, "This is my log message\n")

    o = DummyObject()
    o.set_log_level(IMP.VERBOSE)
    o.add_log()
Пример #5
0
 def do_before_evaluate(self):
     IMP.add_to_log(IMP.TERSE, "Updating dummy " + self.get_name() + "\n")
     self.updated = True