ua_log.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef UA_LOG_H_
  2. #define UA_LOG_H_
  3. /**
  4. @defgroup logging Logging
  5. @brief Logging functionality is externally provided to the open62541 libary.
  6. That is, every thread that wants logging to take place fills a global
  7. variable "logger" with the appropriate callback functions. The UA_LOGLEVEL
  8. preprocessor definition indicates which severity of events (trance, debug,
  9. info, warning, error, fatal) shall be reported. Enabling logs at a certain
  10. level enables all logs at the higher levels also. Furthermore, every
  11. log-message has a category that can be used for filtering or to select the
  12. output medium (file, stdout, ..).
  13. */
  14. typedef enum UA_LoggerCategory {
  15. UA_LOGGERCATEGORY_CONNECTION,
  16. UA_LOGGERCATEGORY_SESSION,
  17. UA_LOGGERCATEGORY_SUBSCRIPTION,
  18. UA_LOGGERCATEGORY_MAINTENANCE,
  19. UA_LOGGERCATEGORY_LOAD,
  20. } UA_LoggerCategory;
  21. typedef struct UA_Logger {
  22. void (*log_trace)(UA_LoggerCategory category, const char *msg, ...);
  23. void (*log_debug)(UA_LoggerCategory category, const char *msg, ...);
  24. void (*log_info)(UA_LoggerCategory category, const char *msg, ...);
  25. void (*log_warning)(UA_LoggerCategory category, const char *msg, ...);
  26. void (*log_error)(UA_LoggerCategory category, const char *msg, ...);
  27. void (*log_fatal)(UA_LoggerCategory category, const char *msg, ...);
  28. } UA_Logger;
  29. /** The logger is a global variable on the stack. So every thread needs to
  30. initialise its own logger. */
  31. static UA_Logger logger;
  32. #if UA_LOGLEVEL <= 100
  33. #define LOG_TRACE(CATEGORY, MSG, ...) do{ logger.log_trace(CATEGORY, MSG, __VA_ARGS__); } while
  34. #else
  35. #define LOG_TRACE(CATEGORY, MSG, ...) do {} while;
  36. #endif
  37. #if UA_LOGLEVEL <= 200
  38. #define LOG_DEBUG(CATEGORY, MSG, ...) do{ logger.log_debug(CATEGORY, MSG, __VA_ARGS__); } while
  39. #else
  40. #define LOG_DEBUG(CATEGORY, MSG, ...) do {} while;
  41. #endif
  42. #if UA_LOGLEVEL <= 300
  43. #define LOG_INFO(CATEGORY, MSG, ...) do{ logger.log_info(CATEGORY, MSG, __VA_ARGS__); } while
  44. #else
  45. #define LOG_INFO(CATEGORY, MSG, ...) do {} while;
  46. #endif
  47. #if UA_LOGLEVEL <= 400
  48. #define LOG_WARNING(CATEGORY, MSG, ...) do{ logger.log_warning(CATEGORY, MSG, __VA_ARGS__); } while
  49. #else
  50. #define LOG_WARNING(CATEGORY, MSG, ...) do {} while;
  51. #endif
  52. #if UA_LOGLEVEL <= 500
  53. #define LOG_ERROR(CATEGORY, MSG, ...) do{ logger.log_error(CATEGORY, MSG, __VA_ARGS__); } while
  54. #else
  55. #define LOG_ERROR(CATEGORY, MSG, ...) do {} while;
  56. #endif
  57. #if UA_LOGLEVEL <= 600
  58. #define LOG_FATAL(CATEGORY, MSG, ...) do{ logger.log_fatal(CATEGORY, MSG, __VA_ARGS__); } while
  59. #else
  60. #define LOG_FATAL(CATEGORY, MSG, ...) do {} while;
  61. #endif
  62. #endif /* UA_LOG_H_ */