C++11 library providing functionality common to all adapters.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB

  1. // This file is under GNU General Public License 3.0
  2. // see LICENSE.txt
  3. #ifndef LIBPEPADAPTER_PEPLOG_HH
  4. #define LIBPEPADAPTER_PEPLOG_HH
  5. #include <sstream>
  6. #include <thread>
  7. #ifdef ANDROID
  8. #include <android/log.h>
  9. #endif
  10. // pEpLog
  11. // ======
  12. // a "to be kept ultra small and simple" logging unit.
  13. // featuring:
  14. // * pEpLog macro that will be eliminated in release-builds (-DNDEBUG=1)
  15. // * thread safe (no interleave when logging from diff threads)
  16. // * OS dependent backend switches:
  17. // * android: __android_log_print
  18. // * all other OS: cout
  19. // * runtime enabled/disabled switch (global)
  20. //
  21. // You might want more and more features, but the feature-policy is very restrictive, and there is a
  22. // primary design goal to keep it simple, maintainable and portable.
  23. //
  24. // How to use:
  25. // include <pEpLog.hh>
  26. // use the macro pEpLog(msg) to do logging
  27. // use NDEBUG=1 to turn logging on/off at compile-time
  28. // use set_enabled(bool) to turn logging on/off at runtime
  29. // use set_enabled_<backend>(bool) to turn logging on/off per backend
  30. #ifdef NDEBUG
  31. #define pEpLog(msg) do{}while(0)
  32. #else
  33. #define pEpLog(msg) \
  34. do { \
  35. std::stringstream msg_ss; \
  36. msg_ss << std::this_thread::get_id() << " - " << __FILE__ << "::" << __FUNCTION__ << " - " << msg; \
  37. pEp::Adapter::pEpLog::log(msg_ss.str()); \
  38. } while(0)
  39. #endif // NDEBUG
  40. namespace pEp {
  41. namespace Adapter {
  42. namespace pEpLog {
  43. void log(std::string msg);
  44. void set_enabled(bool is_enabled);
  45. bool get_enabled();
  46. } // pEpLog
  47. } // Adapter
  48. } // pEp
  49. #endif // LIBPEPADAPTER_PEPLOG_HH