IMP logo
IMP Reference Guide  2.14.0
The Integrative Modeling Platform
log.h
Go to the documentation of this file.
1 /**
2  * \file IMP/log.h
3  * \brief Logging and error reporting support.
4  *
5  * Copyright 2007-2020 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_LOG_H
10 #define IMPKERNEL_LOG_H
11 
12 #include <IMP/kernel_config.h>
13 #include "enums.h"
14 #include "WarningContext.h"
15 #include "Flag.h"
16 #include <string>
17 #if IMP_KERNEL_HAS_LOG4CXX
18 #include <log4cxx/logger.h>
19 #endif
20 
21 IMPKERNEL_BEGIN_NAMESPACE
22 
23 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
24 namespace internal {
25 extern IMPKERNELEXPORT Flag<LogLevel, IMP_HAS_LOG != IMP_SILENT> log_level;
26 }
27 #endif
28 
29 /** \name Logging
30  \anchor log
31  \imp provides tools for controlling the amount of log output produced
32  and directing it to the terminal or a file. Only log messages tagged
33  with a lower level than the current LogLevel are emitted. In addition
34  to a global log level (get_log_level(), set_log_level()), each
35  IMP::Object has an internal log level (IMP::Object::get_log_level(),
36  IMP::Object::set_log_level()) which is used when executing code on
37  that object.
38 
39  Logging is provided by IMP/log.h.
40 
41  People implementing IMP::Object classes should also see IMP_OBJECT_LOG()
42  and IMP::SetLogState.
43 
44  All logging is disabled when \imp is built using \c build='fast'.
45  @{
46  */
47 #ifndef IMP_DOXYGEN
48 #if !IMP_KERNEL_HAS_LOG4CXX
49 //! Push a new log context onto the stack
50 /** A log context is, eg, a function name.
51  */
52 IMPKERNELEXPORT void push_log_context(const char *functionname,
53  const void *object);
54 
55 //! pop the top log context
56 IMPKERNELEXPORT void pop_log_context();
57 
58 //! Write a string to the log
59 IMPKERNELEXPORT void add_to_log(std::string to_write);
60 #endif
61 #endif
62 
63 //! Write a string to the log, for Python
64 IMPKERNELEXPORT void add_to_log(LogLevel level, std::string to_write);
65 
66 //! Set the current global log level
67 /** @note may be overridden by set_log_level of specific objects that inherit
68  from IMP::Object
69  @note this global method should not, currently, be used directly during
70  Model::evaluate() calls.
71 
72  \see get_log_level()
73  \see IMP::Object::set_log_level()
74 */
75 IMPKERNELEXPORT void set_log_level(LogLevel l);
76 
77 //! Set whether log messages are tagged with the current log time
78 IMPKERNELEXPORT void set_log_timer(bool tb);
79 
80 //! Reset the log timer
81 IMPKERNELEXPORT void reset_log_timer();
82 
83 //! Get the currently active global log level
84 /** @note This may not always match the value passed to set_log_level()
85  as objects can temporarily override the global level
86  while they are evaluating.
87 
88  \see set_log_level()
89  \see IMP::Object::set_log_level()
90 
91  */
92 inline LogLevel get_log_level() { return LogLevel(internal::log_level); }
93 
94 #if IMP_KERNEL_HAS_LOG4CXX
95 inline log4cxx::LoggerPtr get_logger() {
96  static log4cxx::LoggerPtr ret = log4cxx::Logger::getLogger("IMP");
97  return ret;
98 }
99 #else
100 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
101 inline bool get_is_log_output(LogLevel l) { return l <= get_log_level(); }
102 #endif
103 #endif
104 
105 /** @} */
106 
107 /** \name Create a progress bar in the terminal
108 
109  @{
110  */
111 //! Set up the progress bar with the passed description.
112 /** \see IMP_PROGRESS_DISPLAY().
113 */
114 IMPKERNELEXPORT void set_progress_display(std::string description,
115  unsigned int steps);
116 
117 //! Set the current progress.
118 /** When it equals the number of steps, the bar is done. */
119 IMPKERNELEXPORT void add_to_progress_display(unsigned int step = 1);
120 
121 /** @} */
122 
123 IMPKERNEL_END_NAMESPACE
124 
125 #endif /* IMPKERNEL_LOG_H */
void set_progress_display(std::string description, unsigned int steps)
Set up the progress bar with the passed description.
LogLevel
The log levels supported by IMP.
Definition: enums.h:19
LogLevel get_log_level()
Get the currently active global log level.
Definition: log.h:92
void add_to_progress_display(unsigned int step=1)
Set the current progress.
void reset_log_timer()
Reset the log timer.
void add_to_log(LogLevel level, std::string to_write)
Write a string to the log, for Python.
Various general useful macros for IMP.
Basic types used by IMP.
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.
Logging and error reporting support.