ua_log.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2014 the contributors as stated in the AUTHORS file
  3. *
  4. * This file is part of open62541. open62541 is free software: you can
  5. * redistribute it and/or modify it under the terms of the GNU Lesser General
  6. * Public License, version 3 (as published by the Free Software Foundation) with
  7. * a static linking exception as stated in the LICENSE file provided with
  8. * open62541.
  9. *
  10. * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. * details.
  14. */
  15. #ifndef UA_LOG_H_
  16. #define UA_LOG_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "ua_config.h"
  21. /**
  22. * @ingroup server
  23. *
  24. * @defgroup logging Logging
  25. *
  26. * @brief Custom logging solutions can be "plugged in" with this interface
  27. *
  28. * @{
  29. */
  30. typedef enum UA_LoggerCategory {
  31. UA_LOGGERCATEGORY_COMMUNICATION,
  32. UA_LOGGERCATEGORY_SERVER,
  33. UA_LOGGERCATEGORY_CLIENT,
  34. UA_LOGGERCATEGORY_USERLAND
  35. } UA_LoggerCategory;
  36. extern UA_EXPORT const char *UA_LoggerCategoryNames[4];
  37. typedef struct UA_Logger {
  38. void (*log_trace)(UA_LoggerCategory category, const char *msg, ...);
  39. void (*log_debug)(UA_LoggerCategory category, const char *msg, ...);
  40. void (*log_info)(UA_LoggerCategory category, const char *msg, ...);
  41. void (*log_warning)(UA_LoggerCategory category, const char *msg, ...);
  42. void (*log_error)(UA_LoggerCategory category, const char *msg, ...);
  43. void (*log_fatal)(UA_LoggerCategory category, const char *msg, ...);
  44. } UA_Logger;
  45. #if UA_LOGLEVEL <= 100
  46. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do { \
  47. if(LOGGER.log_trace) LOGGER.log_trace(CATEGORY, __VA_ARGS__); } while(0)
  48. #else
  49. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do {} while(0)
  50. #endif
  51. #if UA_LOGLEVEL <= 200
  52. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do { \
  53. if(LOGGER.log_debug) LOGGER.log_debug(CATEGORY, __VA_ARGS__); } while(0)
  54. #else
  55. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do {} while(0)
  56. #endif
  57. #if UA_LOGLEVEL <= 300
  58. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do { \
  59. if(LOGGER.log_info) LOGGER.log_info(CATEGORY, __VA_ARGS__); } while(0)
  60. #else
  61. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do {} while(0)
  62. #endif
  63. #if UA_LOGLEVEL <= 400
  64. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do { \
  65. if(LOGGER.log_warning) LOGGER.log_warning(CATEGORY, __VA_ARGS__); } while(0)
  66. #else
  67. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do {} while(0)
  68. #endif
  69. #if UA_LOGLEVEL <= 500
  70. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do { \
  71. if(LOGGER.log_error) LOGGER.log_error(CATEGORY, __VA_ARGS__); } while(0)
  72. #else
  73. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do {} while(0)
  74. #endif
  75. #if UA_LOGLEVEL <= 600
  76. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do { \
  77. if(LOGGER.log_fatal) LOGGER.log_fatal(CATEGORY, __VA_ARGS__); } while(0)
  78. #else
  79. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do {} while(0)
  80. #endif
  81. /** @} */
  82. #ifdef __cplusplus
  83. } // extern "C"
  84. #endif
  85. #endif /* UA_LOG_H_ */