ua_log.h 2.8 KB

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