IMP logo
IMP Reference Guide  2.6.1
The Integrative Modeling Platform
log.py

Show various ways to use the log and control it.

1 ## \example log.py
2 # Show various ways to use the log and control it.
3 
4 import IMP
5 import sys
6 
7 IMP.setup_from_argv(sys.argv, "Log example")
8 
9 class DummyObject(IMP.Object):
10 
11  def __init__(self):
12  IMP.Object.__init__(self, "DummyObject%1%")
13 
14  def add_log(self):
15  # Temporarily (for the duration of the 'with' block) set the
16  # log level and context.
17  # these are done by the IMP_OBJECT_LOG macro in C++
18  with IMP.SetLogState(self.get_log_level()):
19  with IMP.CreateLogContext(self.get_name() + "::add_log"):
20  self.set_was_used(True)
21  IMP.add_to_log(IMP.VERBOSE,
22  "A verbose message in the object\n")
23 
24 # we can set the log level for all of IMP
25 IMP.set_log_level(IMP.TERSE)
26 
27 # we can tell it to print the time each event occurs
29 
30 # we can create a log context (valid for the duration of the 'with' block)
31 with IMP.CreateLogContext("my context"):
32 
33  # we can print a message
34  IMP.add_to_log(IMP.TERSE, "This is my log message\n")
35 
36  o = DummyObject()
37  o.set_log_level(IMP.VERBOSE)
38  o.add_log()