25 #ifndef _ED247_LOGS_H_ 26 #define _ED247_LOGS_H_ 28 #include "ed247_friend_test.h" 36 #define LOG_SHORTFILE (strrchr("/" __FILE__, '/') + 1) 37 #define LOG_STREAM_FILELINE LOG_SHORTFILE << ":" << __LINE__ << " " 40 #define SAY(m) do { SAY_STREAM(ED247_LOG_STREAM, m); } while (0) 43 #define PRINT_ERROR(m) do { if (ED247_LOG_ENABLED(ED247_LOG_LEVEL_ERROR)) ED247_LOG_STREAM << LOG_STREAM_FILELINE << "[ERROR] " << m << std::endl; } while (0) 44 #define PRINT_WARNING(m) do { if (ED247_LOG_ENABLED(ED247_LOG_LEVEL_WARNING)) ED247_LOG_STREAM << LOG_STREAM_FILELINE << "[WARN] " << m << std::endl; } while (0) 45 #define PRINT_INFO(m) do { if (ED247_LOG_ENABLED(ED247_LOG_LEVEL_INFO)) ED247_LOG_STREAM << LOG_STREAM_FILELINE << m << std::endl; } while (0) 46 #define PRINT_DEBUG(m) do { if (ED247_LOG_ENABLED(ED247_LOG_LEVEL_DEBUG)) ED247_LOG_STREAM << LOG_STREAM_FILELINE << m << std::endl; } while (0) 47 #define PRINT_CRAZY(m) do { if (ED247_LOG_ENABLED(ED247_LOG_LEVEL_CRAZY)) ED247_LOG_STREAM << LOG_STREAM_FILELINE << m << std::endl; } while (0) 49 #ifdef SIMULINK_LOGGER_ENABLED 50 # include "Logger.hpp" 51 # define ED247_LOG_STREAM LOG(info, 0) 53 # define ED247_LOG_STREAM ed247::log::get().stream() 56 #define ED247_LOG_ENABLED(level) ed247::log::get().enabled(level) 57 #define SAY_STREAM(stream, m) do { (stream) << LOG_STREAM_FILELINE << m << std::endl; } while (0) 61 struct LIBED247_EXPORT
log 63 static constexpr
const char* ENV_VAR_LEVEL =
"ED247_LOG_LEVEL";
64 static constexpr
const char* ENV_VAR_FILEPATH =
"ED247_LOG_FILEPATH";
67 static log&
get() {
return *((_logger)? _logger : create_logger()); }
72 void reset(
ed247_log_level_t level = ED247_LOG_LEVEL_DEFAULT,
const char* filepath =
nullptr);
75 std::ostream& stream() {
return (_fstream.is_open())? _fstream : std::cerr; }
87 static log* create_logger();
88 static void delete_logger();
90 log() : _level(ED247_LOG_LEVEL_UNSET) { reset(); }
96 std::ofstream _fstream;
97 std::string _filepath;
104 extern LIBED247_EXPORT
void ed247_log_backtrace();
111 exception(std::string message) : _message (message) {};
112 virtual ~
exception()
throw ()
override {}
113 inline const char* what()
const noexcept
override {
return _message.c_str(); }
115 std::string _message;
118 #define THROW_ED247_ERROR(message) \ 120 PRINT_ERROR(message); \ 121 throw ed247::exception(strize() << message); \ 126 inline std::ostream& operator<<(std::ostream& stream,
const ed247_log_level_t& level) {
return (stream << ed247::log::level_name(level)); }
136 #ifdef ENABLE_MEMCHECK 139 void add(
const void* ptr, std::string title);
140 void remove(
const void* ptr);
145 #define MEMCHECK_SAY(ptr, m) SAY("[MEMCHECK " << ptr << "] " << m) 146 #define MEMCHECK_NEW(ptr, title) do { MEMCHECK_SAY(ptr, "NEW " << title); ed247::memcheck::add(ptr, strize() << title); } while (0) 147 #define MEMCHECK_DEL(ptr, title) do { MEMCHECK_SAY(ptr, "DEL " << title); ed247::memcheck::remove(ptr); } while (0) 148 #define MEMCHECK_FREED() ed247::memcheck::assert_freed() 149 #define MEMCHECK_RESET() ed247::memcheck::free() 151 #define MEMCHECK_SAY(ptr, m) 152 #define MEMCHECK_NEW(ptr, title) 153 #define MEMCHECK_DEL(ptr, title) 154 #define MEMCHECK_FREED() 155 #define MEMCHECK_RESET() 162 template<
typename T>
strize& operator<<(T value) { _content << value;
return *
this; }
163 operator std::string()
const {
return _content.str(); }
165 std::stringstream _content;
173 hex_stream(
const void* payload,
int len) : _payload((
const uint8_t*)payload), _len(len) {}
174 LIBED247_EXPORT
friend std::ostream& operator<<(std::ostream& stream,
const hex_stream&);
176 const uint8_t* _payload;
Definition: ed247_logs.h:161
LIBED247_EXPORT const char * ed247_stream_type_string(ed247_stream_type_t stream_type)
ed247_stream_type_t to string conversion
Definition: ed247_conversion.cpp:188
Definition: ed247_logs.h:170
LIBED247_EXPORT const char * ed247_status_string(ed247_status_t status)
ed247_status_t to string conversion
Definition: ed247_conversion.cpp:80
LIBED247_EXPORT const char * ed247_signal_type_string(ed247_signal_type_t signal_type)
ed247_signal_type_t to string conversion
Definition: ed247_conversion.cpp:241
ed247_direction_t
Stream direction.
Definition: ed247.h:153
Definition: ed247_logs.h:108
ed247_signal_type_t
Signal types.
Definition: ed247.h:164
LIBED247_EXPORT const char * ed247_nad_type_string(ed247_nad_type_t nad_type)
ed247_nad_type_t to string conversion
Definition: ed247_conversion.cpp:270
LIBED247_EXPORT const char * ed247_direction_string(ed247_direction_t direction)
ed247_direction_t to string conversion
Definition: ed247_conversion.cpp:102
ed247_nad_type_t
NAD type.
Definition: ed247.h:176
ed247_log_level_t
Logging level.
Definition: ed247.h:78
ed247_status_t
Status codes.
Definition: ed247.h:67
Definition: ed247_channel.cpp:37
ed247_stream_type_t
Stream types.
Definition: ed247.h:132
Definition: ed247_logs.h:61