ua_log.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. typedef enum UA_LoggerCategory {
  29. UA_LOGGINGCATEGORY_CONNECTION,
  30. UA_LOGGINGCATEGORY_SESSION,
  31. UA_LOGGINGCATEGORY_SUBSCRIPTION,
  32. UA_LOGGINGCATEGORY_SERVER
  33. } UA_LoggerCategory;
  34. typedef struct UA_Logger {
  35. void (*log_trace)(UA_LoggerCategory category, const char *msg, ...);
  36. void (*log_debug)(UA_LoggerCategory category, const char *msg, ...);
  37. void (*log_info)(UA_LoggerCategory category, const char *msg, ...);
  38. void (*log_warning)(UA_LoggerCategory category, const char *msg, ...);
  39. void (*log_error)(UA_LoggerCategory category, const char *msg, ...);
  40. void (*log_fatal)(UA_LoggerCategory category, const char *msg, ...);
  41. } UA_Logger;
  42. #if UA_LOGLEVEL <= 100
  43. #define UA_LOG_TRACE(CATEGORY, MSG, ...) do { logger.log_trace(CATEGORY, MSG, __VA_ARGS__); } while(0)
  44. #else
  45. #define UA_LOG_TRACE(CATEGORY, MSG, ...) do {} while(0)
  46. #endif
  47. #if UA_LOGLEVEL <= 200
  48. #define UA_LOG_DEBUG(CATEGORY, MSG, ...) do { logger.log_debug(CATEGORY, MSG, __VA_ARGS__); } while(0)
  49. #else
  50. #define UA_LOG_DEBUG(CATEGORY, MSG, ...) do {} while(0)
  51. #endif
  52. #if UA_LOGLEVEL <= 300
  53. #define UA_LOG_INFO(CATEGORY, MSG, ...) do { logger.log_info(CATEGORY, MSG, __VA_ARGS__); } while(0)
  54. #else
  55. #define UA_LOG_INFO(CATEGORY, MSG, ...) do {} while(0)
  56. #endif
  57. #if UA_LOGLEVEL <= 400
  58. #define UA_LOG_WARNING(CATEGORY, MSG, ...) do { logger.log_warning(CATEGORY, MSG, __VA_ARGS__); } while(0)
  59. #else
  60. #define UA_LOG_WARNING(CATEGORY, MSG, ...) do {} while(0)
  61. #endif
  62. #if UA_LOGLEVEL <= 500
  63. #define UA_LOG_ERROR(CATEGORY, MSG, ...) do { logger.log_error(CATEGORY, MSG, __VA_ARGS__); } while(0)
  64. #else
  65. #define UA_LOG_ERROR(CATEGORY, MSG, ...) do {} while(0)
  66. #endif
  67. #if UA_LOGLEVEL <= 600
  68. #define UA_LOG_FATAL(CATEGORY, MSG, ...) do { logger.log_fatal(CATEGORY, MSG, __VA_ARGS__); } while(0)
  69. #else
  70. #define UA_LOG_FATAL(CATEGORY, MSG, ...) do {} while(0)
  71. #endif
  72. #ifdef __cplusplus
  73. } // extern "C"
  74. #endif
  75. #endif /* UA_LOG_H_ */