IMP  2.0.0
The Integrative Modeling Platform
base/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-2013 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 "internal/static.h"
16 #include <iostream>
17 #include <cstdlib>
18 #include <string>
19 #include <sstream>
20 #if IMP_BASE_HAS_LOG4CXX
21 #include <log4cxx/logger.h>
22 #endif
23 
24 IMPBASE_BEGIN_NAMESPACE
25 
26 /** \name Logging
27  \anchor log
28  \imp provides tools for controlling the amount of log output produced
29  and directing it to the terminal or a file. Only log messages tagged
30  with a lower level than the current LogLevel are emitted. In addition
31  to a global log level (get_log_level(), set_log_level()), each
32  IMP::Object has an internal log level (IMP::Object::get_log_level(),
33  IMP::Object::set_log_level()) which is used when executing code on
34  that object.
35 
36  Logging is provided by IMP/log.h.
37 
38  People implementing IMP::Object classes should also see IMP_OBJECT_LOG()
39  and IMP::SetLogState.
40 
41  All logging is disabled when \imp is built using \c build='fast'.
42  @{
43  */
44 #ifndef IMP_DOXYGEN
45 #if !IMP_BASE_HAS_LOG4CXX
46 //! Push a new log context onto the stack
47 /** A log context is, eg, a function name.
48  */
49 IMPBASEEXPORT void push_log_context(const char *functionname,
50  const void *object);
51 
52 //! pop the top log context
53 IMPBASEEXPORT void pop_log_context();
54 
55 //! Write a string to the log
56 IMPBASEEXPORT void add_to_log(std::string to_write);
57 #endif
58 #endif
59 
60 
61 //! Write a string to the log, for python
62 IMPBASEEXPORT void add_to_log(LogLevel level, std::string to_write);
63 
64 //! Set the current global log level
65 /** Note that this should not, currently, be used directly
66  during Model::evaluate() calls. */
67 IMPBASEEXPORT void set_log_level(LogLevel l);
68 
69 //! Set whether log messages are tagged with the current log time
70 IMPBASEEXPORT void set_log_timer(bool tb);
71 
72 //! Reset the log timer
73 IMPBASEEXPORT void reset_log_timer();
74 
75 
76 //! Get the currently active log level
77 /** This may not always match the value passed to set_log_level()
78  as objects can temporarily override the global level
79  while they are evaluating.
80  */
82 {
83  return LogLevel(internal::log_level);
84 }
85 
86 
87 #if IMP_BASE_HAS_LOG4CXX
88 inline log4cxx::LoggerPtr get_logger() {
89  static log4cxx::LoggerPtr ret = log4cxx::Logger::getLogger("IMP");
90  return ret;
91 }
92 #else
93 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
94 inline bool get_is_log_output(LogLevel l)
95 {
96  return l <= get_log_level();
97 }
98 #endif
99 #endif
100 
101 /** @} */
102 
103 
104 /** \name Create a progress bar in the terminal
105 
106  @{
107  */
108 /** Set up the progress bar with the passed description.
109 
110  See IMP_PROGRESS_DISPLAY().
111 */
112 IMPBASEEXPORT void set_progress_display(std::string description,
113  unsigned int steps);
114 /** Set the current progress. When it equals the number of steps,
115  the bar is done.*/
116 IMPBASEEXPORT void add_to_progress_display(unsigned int step = 1);
117 
118 /** @} */
119 
120 IMPBASE_END_NAMESPACE
121 
122 
123 #endif /* IMPBASE_LOG_H */