5 #ifndef HERALD_SENSOR_LOGGER_H
6 #define HERALD_SENSOR_LOGGER_H
8 #include "../datatype/bluetooth_state.h"
20 #ifdef HERALD_LOG_LEVEL
23 #if HERALD_LOG_LEVEL != 0
24 #define HLOGGER(_ctxT) \
25 herald::data::SensorLogger<typename _ctxT::logging_sink_type> logger;
26 #define HLOGGERINIT(_ctx,_subsystem,_category) ,logger(_ctx.getLoggingSink(),_subsystem,_category)
31 #if HERALD_LOG_LEVEL == 4
32 #define HDBG(_msg, ...) mImpl->logger.debug(_msg, ##__VA_ARGS__);
33 #define HTDBG(_msg, ...) logger.debug(_msg, ##__VA_ARGS__);
34 #define HLOG(_msg, ...) mImpl->logger.info(_msg, ##__VA_ARGS__);
35 #define HTLOG(_msg, ...) logger.info(_msg, ##__VA_ARGS__);
36 #define HERR(_msg, ...) mImpl->logger.fault(_msg, ##__VA_ARGS__);
37 #define HTERR(_msg, ...) logger.fault(_msg, ##__VA_ARGS__);
40 #if HERALD_LOG_LEVEL == 3
43 #define HLOG(_msg, ...) mImpl->logger.info(_msg, ##__VA_ARGS__);
44 #define HTLOG(_msg, ...) logger.info(_msg, ##__VA_ARGS__);
45 #define HERR(_msg, ...) mImpl->logger.fault(_msg, ##__VA_ARGS__);
46 #define HTERR(_msg, ...) logger.fault(_msg, ##__VA_ARGS__);
50 #if HERALD_LOG_LEVEL == 2
53 #define HLOG(_msg, ...) mImpl->logger.info(_msg, ##__VA_ARGS__);
54 #define HTLOG(_msg, ...) logger.info(_msg, ##__VA_ARGS__);
55 #define HERR(_msg, ...) mImpl->logger.fault(_msg, ##__VA_ARGS__);
56 #define HTERR(_msg, ...) logger.fault(_msg, ##__VA_ARGS__);
59 #if HERALD_LOG_LEVEL == 1
64 #define HERR(_msg, ...) mImpl->logger.fault(_msg, ##__VA_ARGS__);
65 #define HTERR(_msg, ...) logger.fault(_msg, ##__VA_ARGS__);
68 #if HERALD_LOG_LEVEL == 0
70 #define HLOGGER(_ctxT)
71 #define HLOGGERINIT(...)
83 #define HLOGGER(_ctxT)
84 #define HLOGGERINIT(...)
98 enum class SensorLoggerLevel : int {
125 void tprintf(std::stringstream& os,
const std::string& format)
128 for (
auto c : format ) {
130 if (format.size() > pos + 1 && format.at(pos + 1) ==
'}') {
131 tprintf(os, format.substr(pos + 2));
133 tprintf(os, format.substr(pos + 1));
142 template<
typename... Targs>
143 void tprintf(std::stringstream& os,
const std::string& format, std::uint8_t value, Targs... Fargs)
146 for (
auto c : format ) {
148 os << std::uint16_t(value);
149 if (format.size() > pos + 1 && format.at(pos + 1) ==
'}') {
150 tprintf(os, format.substr(pos + 2), Fargs...);
152 tprintf(os, format.substr(pos + 1), Fargs...);
161 template<
typename... Targs>
162 void tprintf(std::stringstream& os,
const std::string& format, std::int8_t value, Targs... Fargs)
165 for (
auto c : format ) {
167 os << std::int16_t(value);
168 if (format.size() > pos + 1 && format.at(pos + 1) ==
'}') {
169 tprintf(os, format.substr(pos + 2), Fargs...);
171 tprintf(os, format.substr(pos + 1), Fargs...);
202 void tprintf(std::stringstream& os,
const std::string& format, T value)
205 for (
auto c : format ) {
208 if (format.size() > pos + 1 && format.at(pos + 1) ==
'}') {
209 tprintf(os, format.substr(pos + 2));
211 tprintf(os, format.substr(pos + 1));
220 template<
typename FirstT,
typename SecondT,
typename... RestT>
221 void tprintf(std::stringstream& os,
const std::string& format, FirstT first, SecondT second, RestT... rest)
224 for (
auto c : format ) {
227 if (format.size() > pos + 1 && format.at(pos + 1) ==
'}') {
228 tprintf(os, format.substr(pos + 2), second, rest...);
230 tprintf(os, format.substr(pos + 1), second, rest...);
267 template <
typename LoggingSinkT>
270 SensorLogger(LoggingSinkT& sink, std::string subsystem, std::string category)
271 : mSink(sink), mSubsystem(subsystem), mCategory(category)
277 : mSink(other.mSink), mSubsystem(other.mSubsystem), mCategory(other.mCategory)
283 : mSink(other.mSink), mSubsystem(other.mSubsystem), mCategory(other.mCategory)
291 mSubsystem = other.mSubsystem;
292 mCategory = other.mCategory;
299 mSubsystem = other.mSubsystem;
300 mCategory = other.mCategory;
311 template <
typename ... Types>
312 void debug(
const std::string& message,
const Types&... args) {
313 const int size =
sizeof...(args);
315 log(SensorLoggerLevel::debug,message);
317 std::stringstream os;
318 tprintf(os,message,args...);
320 log(SensorLoggerLevel::debug, os.str());
324 template <
typename ... Types>
325 void info(
const std::string& message,
const Types&... args) {
326 const int size =
sizeof...(args);
328 log(SensorLoggerLevel::debug,message);
330 std::stringstream os;
331 tprintf(os,message,args...);
333 log(SensorLoggerLevel::info, os.str());
337 template <
typename ... Types>
338 void fault(
const std::string& message,
const Types&... args) {
339 const int size =
sizeof...(args);
341 log(SensorLoggerLevel::debug,message);
343 std::stringstream os;
344 tprintf(os,message,args...);
346 log(SensorLoggerLevel::fault, os.str());
351 inline void log(SensorLoggerLevel lvl, std::string msg) {
352 mSink.log(mSubsystem, mCategory, lvl, msg);
356 std::string mSubsystem;
357 std::string mCategory;
Definition: sensor_logger.h:268
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15