ua_log.h 2.8 KB

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