ua_log.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_USERLAND
  34. } UA_LoggerCategory;
  35. extern UA_EXPORT const char *UA_LoggerCategoryNames[3];
  36. typedef struct UA_Logger {
  37. void (*log_trace)(UA_LoggerCategory category, const char *msg, ...);
  38. void (*log_debug)(UA_LoggerCategory category, const char *msg, ...);
  39. void (*log_info)(UA_LoggerCategory category, const char *msg, ...);
  40. void (*log_warning)(UA_LoggerCategory category, const char *msg, ...);
  41. void (*log_error)(UA_LoggerCategory category, const char *msg, ...);
  42. void (*log_fatal)(UA_LoggerCategory category, const char *msg, ...);
  43. } UA_Logger;
  44. #if UA_LOGLEVEL <= 100
  45. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do { \
  46. if(LOGGER.log_trace) LOGGER.log_trace(CATEGORY, __VA_ARGS__); } while(0)
  47. #else
  48. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do {} while(0)
  49. #endif
  50. #if UA_LOGLEVEL <= 200
  51. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do { \
  52. if(LOGGER.log_debug) LOGGER.log_debug(CATEGORY, __VA_ARGS__); } while(0)
  53. #else
  54. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do {} while(0)
  55. #endif
  56. #if UA_LOGLEVEL <= 300
  57. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do { \
  58. if(LOGGER.log_info) LOGGER.log_info(CATEGORY, __VA_ARGS__); } while(0)
  59. #else
  60. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do {} while(0)
  61. #endif
  62. #if UA_LOGLEVEL <= 400
  63. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do { \
  64. if(LOGGER.log_warning) LOGGER.log_warning(CATEGORY, __VA_ARGS__); } while(0)
  65. #else
  66. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do {} while(0)
  67. #endif
  68. #if UA_LOGLEVEL <= 500
  69. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do { \
  70. if(LOGGER.log_error) LOGGER.log_error(CATEGORY, __VA_ARGS__); } while(0)
  71. #else
  72. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do {} while(0)
  73. #endif
  74. #if UA_LOGLEVEL <= 600
  75. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do { \
  76. if(LOGGER.log_fatal) LOGGER.log_fatal(CATEGORY, __VA_ARGS__); } while(0)
  77. #else
  78. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do {} while(0)
  79. #endif
  80. /** @} */
  81. #ifdef __cplusplus
  82. } // extern "C"
  83. #endif
  84. #endif /* UA_LOG_H_ */