IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
log.py
1## \example log.py
2# Show various ways to use the log and control it.
3
4import IMP
5import sys
6
7IMP.setup_from_argv(sys.argv, "Log example")
8
9
10class DummyObject(IMP.Object):
11
12 def __init__(self):
13 super().__init__("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
27IMP.set_log_level(IMP.TERSE)
28
29# we can tell it to print the time each event occurs
31
32# we can create a log context (valid for the duration of the 'with' block)
33with 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()
Create a new log context.
Common base class for heavy weight IMP objects.
Definition Object.h:111
A class to change and restore log state.
Definition SetLogState.h:30
void set_log_level(LogLevel l)
Set the current global log level.
void set_log_timer(bool tb)
Set whether log messages are tagged with the current log time.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.
void add_to_log(LogLevel level, std::string to_write)
Write a string to the log, for Python.