IMP logo
IMP Reference Guide  develop.cb469e0f11,2024/05/28
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 
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
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()
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:111
A class to change and restore log state.
Definition: SetLogState.h:30
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.