IMP  2.1.1
The Integrative Modeling Platform
base/log.py

Show various ways to use the log and control it.

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