ua_log.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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_COMMUNICATION,
  38. UA_LOGCATEGORY_SERVER,
  39. UA_LOGCATEGORY_CLIENT,
  40. UA_LOGCATEGORY_USERLAND
  41. } UA_LogCategory;
  42. typedef void (*UA_Logger)(UA_LogLevel level, UA_LogCategory category, const char *msg, ...);
  43. #if UA_LOGLEVEL <= 100
  44. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do { \
  45. if(LOGGER) LOGGER(UA_LOGLEVEL_TRACE, CATEGORY, __VA_ARGS__); } while(0)
  46. #else
  47. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do {} while(0)
  48. #endif
  49. #if UA_LOGLEVEL <= 200
  50. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do { \
  51. if(LOGGER) LOGGER(UA_LOGLEVEL_DEBUG, CATEGORY, __VA_ARGS__); } while(0)
  52. #else
  53. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do {} while(0)
  54. #endif
  55. #if UA_LOGLEVEL <= 300
  56. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do { \
  57. if(LOGGER) LOGGER(UA_LOGLEVEL_INFO, CATEGORY, __VA_ARGS__); } while(0)
  58. #else
  59. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do {} while(0)
  60. #endif
  61. #if UA_LOGLEVEL <= 400
  62. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do { \
  63. if(LOGGER) LOGGER(UA_LOGLEVEL_WARNING, CATEGORY, __VA_ARGS__); } while(0)
  64. #else
  65. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do {} while(0)
  66. #endif
  67. #if UA_LOGLEVEL <= 500
  68. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do { \
  69. if(LOGGER) LOGGER(UA_LOGLEVEL_ERROR, CATEGORY, __VA_ARGS__); } while(0)
  70. #else
  71. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do {} while(0)
  72. #endif
  73. #if UA_LOGLEVEL <= 600
  74. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do { \
  75. if(LOGGER) LOGGER(UA_LOGLEVEL_FATAL, CATEGORY, __VA_ARGS__); } while(0)
  76. #else
  77. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do {} while(0)
  78. #endif
  79. /** @} */
  80. #ifdef __cplusplus
  81. } // extern "C"
  82. #endif
  83. #endif /* UA_LOG_H_ */