RMF
log.h
Go to the documentation of this file.
1 /**
2  * \file RMF/log.h
3  * \brief Functions and macros for logging.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef RMF_LOG_H
10 #define RMF_LOG_H
11 
12 #include <string>
13 
14 #include "RMF/config.h"
15 #if RMF_HAS_LOG4CXX
16 #include <log4cxx/logger.h> // IWYU pragma: export
17 #include <log4cxx/ndc.h> // IWYU pragma: export
18 #include <log4cxx/helpers/messagebuffer.h> // IWYU pragma: export
19 #include <log4cxx/logger.h> // IWYU pragma: export
20 #endif
21 
22 RMF_ENABLE_WARNINGS
23 
24 namespace RMF {
25 
26 #if RMF_HAS_LOG4CXX
27 RMFEXPORT log4cxx::LoggerPtr get_logger();
28 #endif
29 
30 /** Set the log level from a string. Supported values are:
31  - Trace
32  - Info
33  - Warn
34  - Error
35  - Off
36 
37  Log4CXX is required for logging to be supported.
38 */
39 RMFEXPORT void set_log_level(std::string level);
40 
41 } /* namespace RMF */
42 
43 #if RMF_HAS_LOG4CXX
44 
45 #define RMF_TRACE(expr) LOG4CXX_TRACE(RMF::get_logger(), expr)
46 #define RMF_DEBUG(expr) LOG4CXX_DEBUG(RMF::get_logger(), expr)
47 #define RMF_INFO(expr) LOG4CXX_INFO(RMF::get_logger(), expr)
48 #define RMF_WARN(expr) LOG4CXX_WARN(RMF::get_logger(), expr)
49 #define RMF_ERROR(expr) LOG4CXX_ERROR(RMF::get_logger(), expr)
50 #define RMF_FATAL(expr) LOG4CXX_FATAL(RMF::get_logger(), expr)
51 #define RMF_CONTEXT(expr) log4cxx::NDC _log_context(expr)
52 
53 #else
54 #define RMF_TRACE(expr)
55 #define RMF_DEBUG(expr)
56 #define RMF_INFO(expr)
57 #define RMF_WARN(expr)
58 #define RMF_ERROR(expr)
59 #define RMF_FATAL(expr)
60 #define RMF_CONTEXT(expr)
61 
62 #endif
63 
64 RMF_DISABLE_WARNINGS
65 
66 #endif /* RMF_LOG_H */
void set_log_level(std::string level)