IMP logo
IMP Reference Guide  2.9.0
The Integrative Modeling Platform
log.py
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()
Strings setup_from_argv(const Strings &argv, std::string description, std::string positional_description, int num_positional)
Common base class for heavy weight IMP objects.
Definition: Object.h:106
A class to change and restore log state.
Definition: SetLogState.h:31
void add_to_log(LogLevel level, std::string to_write)
Write a string to the log, for Python.
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.
Create a new log context.