ua_log.h 2.8 KB

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