ua_log.h 2.7 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. * @defgroup logging Logging
  23. *
  24. * @brief Custom logging solutions can be "plugged in" with this interface
  25. *
  26. * @{
  27. */
  28. typedef enum {
  29. UA_LOGLEVEL_TRACE,
  30. UA_LOGLEVEL_DEBUG,
  31. UA_LOGLEVEL_INFO,
  32. UA_LOGLEVEL_WARNING,
  33. UA_LOGLEVEL_ERROR,
  34. UA_LOGLEVEL_FATAL
  35. } UA_LogLevel;
  36. typedef enum {
  37. UA_LOGCATEGORY_NETWORK,
  38. UA_LOGCATEGORY_SECURECHANNEL,
  39. UA_LOGCATEGORY_SESSION,
  40. UA_LOGCATEGORY_SERVER,
  41. UA_LOGCATEGORY_CLIENT,
  42. UA_LOGCATEGORY_USERLAND
  43. } UA_LogCategory;
  44. typedef void (*UA_Logger)(UA_LogLevel level, UA_LogCategory category, const char *msg, ...);
  45. #if UA_LOGLEVEL <= 100
  46. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do { \
  47. if(LOGGER) LOGGER(UA_LOGLEVEL_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) LOGGER(UA_LOGLEVEL_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) LOGGER(UA_LOGLEVEL_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) LOGGER(UA_LOGLEVEL_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) LOGGER(UA_LOGLEVEL_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) LOGGER(UA_LOGLEVEL_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_ */