IMP  2.4.0
The Integrative Modeling Platform
log.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base/log.h
3  * \brief Logging and error reporting support.
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPBASE_LOG_H
10 #define IMPBASE_LOG_H
11 
12 #include <IMP/base/base_config.h>
13 #include "enums.h"
14 #include "WarningContext.h"
15 #include "Flag.h"
16 #include <string>
17 #if IMP_BASE_HAS_LOG4CXX
18 #include <log4cxx/logger.h>
19 #endif
20 
21 IMPBASE_BEGIN_NAMESPACE
22 
23 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
24 namespace internal {
25 extern IMPBASEEXPORT 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/base/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_BASE_HAS_LOG4CXX
49 //! Push a new log context onto the stack
50 /** A log context is, eg, a function name.
51  */
52 IMPBASEEXPORT void push_log_context(const char *functionname,
53  const void *object);
54 
55 //! pop the top log context
56 IMPBASEEXPORT void pop_log_context();
57 
58 //! Write a string to the log
59 IMPBASEEXPORT void add_to_log(std::string to_write);
60 #endif
61 #endif
62 
63 //! Write a string to the log, for Python
64 IMPBASEEXPORT 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::base::Object
69  @note this global method should not, currently, be used directly during
70  kernel::Model::evaluate() calls.
71 
72  \see get_log_level()
73  \see IMP::base::Object::set_log_level()
74 */
75 IMPBASEEXPORT void set_log_level(LogLevel l);
76 
77 //! Set whether log messages are tagged with the current log time
78 IMPBASEEXPORT void set_log_timer(bool tb);
79 
80 //! Reset the log timer
81 IMPBASEEXPORT void reset_log_timer();
82 
83 //! Get the currently active global log level
84 /** Get the currently active global log level
85 
86  @note This may not always match the value passed to set_log_level()
87  as objects can temporarily override the global level
88  while they are evaluating.
89 
90  \see set_log_level()
91  \see IMP::base::Object::set_log_level()
92 
93  */
94 inline LogLevel get_log_level() { return LogLevel(internal::log_level); }
95 
96 #if IMP_BASE_HAS_LOG4CXX
97 inline log4cxx::LoggerPtr get_logger() {
98  static log4cxx::LoggerPtr ret = log4cxx::Logger::getLogger("IMP");
99  return ret;
100 }
101 #else
102 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
103 inline bool get_is_log_output(LogLevel l) { return l <= get_log_level(); }
104 #endif
105 #endif
106 
107 /** @} */
108 
109 /** \name Create a progress bar in the terminal
110 
111  @{
112  */
113 //! Set up the progress bar with the passed description.
114 /** \see IMP_PROGRESS_DISPLAY().
115 */
116 IMPBASEEXPORT void set_progress_display(std::string description,
117  unsigned int steps);
118 
119 //! Set the current progress.
120 /** When it equals the number of steps, the bar is done. */
121 IMPBASEEXPORT void add_to_progress_display(unsigned int step = 1);
122 
123 /** @} */
124 
125 IMPBASE_END_NAMESPACE
126 
127 #endif /* IMPBASE_LOG_H */
void set_log_timer(bool tb)
Set whether log messages are tagged with the current log time.
LogLevel
The log levels supported by IMP.
Definition: enums.h:20
void reset_log_timer()
Reset the log timer.
void set_log_level(LogLevel l)
Set the current global log level.
void set_progress_display(std::string description, unsigned int steps)
Set up the progress bar with the passed description.
LogLevel get_log_level()
Get the currently active global log level.
Definition: log.h:94
void add_to_log(LogLevel level, std::string to_write)
Write a string to the log, for Python.
Various general useful macros for IMP.
void add_to_progress_display(unsigned int step=1)
Set the current progress.
Basic types used by IMP.
Logging and error reporting support.