MIP_SDK  v3.0.0-521-gd8dd613
MicroStrain Communications Library for embedded systems
logging.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <microstrain/logging.h>
4 
5 #include <microstrain/span.hpp>
6 
7 #include <string>
8 
9 /*
10 namespace microstrain {
11 namespace logging {
12 
16 
17  // enum LogLevel : ::microstrain::C::microstrain_log_level
18  // {
19  // LEVEL_NONE = MICROSTRAIN_LOG_LEVEL_OFF,
20  // LEVEL_FATAL = MICROSTRAIN_LOG_LEVEL_FATAL,
21  // LEVEL_ERROR = MICROSTRAIN_LOG_LEVEL_ERROR,
22  // LEVEL_WARN = MICROSTRAIN_LOG_LEVEL_WARN,
23  // LEVEL_INFO = MICROSTRAIN_LOG_LEVEL_INFO,
24  // LEVEL_DEBUG = MICROSTRAIN_LOG_LEVEL_DEBUG,
25  // LEVEL_TRACE = MICROSTRAIN_LOG_LEVEL_TRACE,
26  // };
27  using Level = ::microstrain::C::microstrain_log_level;
28 
29  using Callback = ::microstrain::C::microstrain_log_callback;
30 
31  inline void init(Callback callback, Level max_level, void* user=nullptr)
32  {
33  return MICROSTRAIN_LOG_INIT(callback, max_level, user);
34  }
35 
36  inline Callback get_callback()
37  {
38 #if MICROSTRAIN_ENABLE_LOGGING
39  return ::microstrain::C::microstrain_logging_callback();
40 #else
41  return nullptr;
42 #endif
43  }
44 
45  inline Level max_level()
46  {
47  #if MICROSTRAIN_ENABLE_LOGGING
48  return ::microstrain::C::microstrain_logging_level();
49  #else
50  return LogLevel::OFF;
51  #endif
52  }
53 
54  inline void* user_pointer()
55  {
56 #if MICROSTRAIN_ENABLE_LOGGING
57  return ::microstrain::C::microstrain_logging_user_data();
58 #else
59  return nullptr;
60 #endif
61  }
62 
63  inline void log(Level level, const char* fmt, ...)
64  {
65 #if MICROSTRAIN_ENABLE_LOGGING
66  va_list args;
67  va_start(args, fmt);
68  ::microstrain::C::microstrain_logging_log_v(level, fmt, args);
69  va_end(args);
70 #endif
71  }
72 
75 
76 } // namespace logging
77 } // namespace microstrain
78 */
logging.h
span.hpp