1 #ifndef INCLUDE_ECA_LOGGER_H 2 #define INCLUDE_ECA_LOGGER_H 3 4 #include <string> 5 #include <pthread.h> 6 7 /** 8 * Forward declarations 9 */ 10 11 class ECA_LOGGER_INTERFACE; 12 13 /** 14 * A logging subsystem implemented as a singleton 15 * class. 16 * 17 * Related design patterns: 18 * - Singleton (GoF127) 19 * 20 * @author Kai Vehmanen 21 */ 22 class ECA_LOGGER { 23 24 public: 25 26 /** 27 * Log level is a bitmasked integer value that is used to 28 * categorize different log message types. 29 * 30 * disabled = no output 31 * 32 * errors = error messages 33 * 34 * info = high-level info about user-visible objects 35 * and concepts, warning messages; low volume 36 * 37 * subsystems = notifications of control flow transitions 38 * between high-level subsystems; low volume 39 * 40 * module_names = include module names in log output 41 * 42 * user_objects = info about user-visible objects (audio i/o, 43 * chain operators, controllers); high volume 44 * 45 * system_objects = info about internal objects; high volume 46 * 47 * functions = info about internal operation of individual 48 * functions and algorithms; high volume bursts 49 * 50 * continuous = debug info printed for during processing; 51 * continuous high volume 52 * 53 * eiam_return_values = return values for EIAM commands 54 * 55 * @see level_to_string() 56 */ 57 typedef enum { 58 disabled = 0, 59 errors = 1, 60 info = 2, 61 subsystems = 4, 62 module_names = 8, 63 user_objects = 16, 64 system_objects = 32, 65 functions = 64, 66 continuous = 128, 67 eiam_return_values = 256 68 } Msg_level_t; 69 70 /** 71 * Returns a reference to a logging system 72 * implementation object. 73 * 74 * Note! Return value is a reference to 75 * avoid accidental deletion of 76 * the singleton object. 77 */ 78 static ECA_LOGGER_INTERFACE& instance(void); 79 80 /** 81 * Replace the default logging sybsystem 82 * with a custom implementation. 83 * 84 * Note! Ownership of 'logger' is transferred 85 * to the singleton object. 86 */ 87 static void attach_logger(ECA_LOGGER_INTERFACE* logger); 88 89 /** 90 * Detaches the current logger implementation. 91 */ 92 static void detach_logger(void); 93 94 /** 95 * Returns description of log level 'arg'. 96 */ 97 static const char* level_to_string(Msg_level_t arg); 98 99 private: 100 101 static ECA_LOGGER_INTERFACE* interface_impl_repp; 102 static pthread_mutex_t lock_rep; 103 104 /** 105 * @name Constructors and destructors 106 * 107 * To prevent accidental use, located in private scope and 108 * without a valid definition. 109 */ 110 /*@{*/ 111 112 ECA_LOGGER(void); 113 ECA_LOGGER(const ECA_LOGGER&); 114 ECA_LOGGER& operator=(const ECA_LOGGER&); 115 ~ECA_LOGGER(void); 116 117 /*@}*/ 118 }; 119 120 /** 121 * Macro definitions 122 */ 123 124 /** 125 * Issues a log message. 126 * 127 * @param x log level, type 'ECA_LOGGER::Msg_level_t' 128 * @param y log message, type 'const std:string&' 129 */ 130 #define ECA_LOG_MSG(x,y) \ 131 do { ECA_LOGGER::instance().msg(x, __FILE__, y); } while(0) 132 133 /** 134 * Issue a log message, but do not print out the module prefix. 135 * A variant of ECA_LOG_MSG(). 136 */ 137 #define ECA_LOG_MSG_NOPREFIX(x,y) \ 138 do { ECA_LOGGER::instance().msg(x, std::string(), y); } while(0) 139 140 /** 141 * To make ECA_LOG_MSG work we need to include the 142 * public interface ECA_LOGGER_INTERFACE. 143 */ 144 145 #include "eca-logger-interface.h" 146 147 #endif /* INCLUDE_ECA_LOGGER_H */ 148