home
about
news
download
doc
source
systems
tests
bugs
contact
IMP Reference Guide
2.21.0
The Integrative Modeling Platform
IMP Manual
Reference Guide
Tutorial Index
Modules
Classes
Examples
version 2.21.0
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
10
class
DummyObject(
IMP.Object
):
11
12
def
__init__(self):
13
IMP.Object.__init__(self,
"DummyObject%1%"
)
14
15
def
add_log(self):
16
# Temporarily (for the duration of the 'with' block) set the
17
# log level and context.
18
# these are done by the IMP_OBJECT_LOG macro in C++
19
with
IMP.SetLogState
(self.get_log_level()):
20
with
IMP.CreateLogContext
(self.get_name() +
"::add_log"
):
21
self.set_was_used(
True
)
22
IMP.add_to_log
(IMP.VERBOSE,
23
"A verbose message in the object\n"
)
24
25
26
# we can set the log level for all of IMP
27
IMP.set_log_level
(IMP.TERSE)
28
29
# we can tell it to print the time each event occurs
30
IMP.set_log_timer
(
True
)
31
32
# we can create a log context (valid for the duration of the 'with' block)
33
with
IMP.CreateLogContext
(
"my context"
):
34
35
# we can print a message
36
IMP.add_to_log
(IMP.TERSE,
"This is my log message\n"
)
37
38
o = DummyObject()
39
o.set_log_level(IMP.VERBOSE)
40
o.add_log()