ua_log.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2014-2016 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. * Logging
  23. * -------
  24. * Servers and clients may contain a logger. Every logger needs to implement the
  25. * `UA_Logger` signature. An example logger that writes to stdout is provided in
  26. * the plugins folder.
  27. *
  28. * Every log-message consists of a log-level, a log-category and a string
  29. * message content. The timestamp of the log-message is created within the
  30. * logger.
  31. */
  32. typedef enum {
  33. UA_LOGLEVEL_TRACE,
  34. UA_LOGLEVEL_DEBUG,
  35. UA_LOGLEVEL_INFO,
  36. UA_LOGLEVEL_WARNING,
  37. UA_LOGLEVEL_ERROR,
  38. UA_LOGLEVEL_FATAL
  39. } UA_LogLevel;
  40. typedef enum {
  41. UA_LOGCATEGORY_NETWORK,
  42. UA_LOGCATEGORY_SECURECHANNEL,
  43. UA_LOGCATEGORY_SESSION,
  44. UA_LOGCATEGORY_SERVER,
  45. UA_LOGCATEGORY_CLIENT,
  46. UA_LOGCATEGORY_USERLAND
  47. } UA_LogCategory;
  48. /**
  49. * The signature of the logger. The msg string and following varargs are
  50. * formatted according to the rules of the printf command.
  51. *
  52. * Do not use the logger directly but make use of the following macros that take
  53. * the minimum log-level defined in ua_config.h into account. */
  54. typedef void (*UA_Logger)(UA_LogLevel level, UA_LogCategory category, const char *msg, ...);
  55. #if UA_LOGLEVEL <= 100
  56. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do { \
  57. if(LOGGER) LOGGER(UA_LOGLEVEL_TRACE, CATEGORY, __VA_ARGS__); } while(0)
  58. #else
  59. #define UA_LOG_TRACE(LOGGER, CATEGORY, ...) do {} while(0)
  60. #endif
  61. #if UA_LOGLEVEL <= 200
  62. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do { \
  63. if(LOGGER) LOGGER(UA_LOGLEVEL_DEBUG, CATEGORY, __VA_ARGS__); } while(0)
  64. #else
  65. #define UA_LOG_DEBUG(LOGGER, CATEGORY, ...) do {} while(0)
  66. #endif
  67. #if UA_LOGLEVEL <= 300
  68. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do { \
  69. if(LOGGER) LOGGER(UA_LOGLEVEL_INFO, CATEGORY, __VA_ARGS__); } while(0)
  70. #else
  71. #define UA_LOG_INFO(LOGGER, CATEGORY, ...) do {} while(0)
  72. #endif
  73. #if UA_LOGLEVEL <= 400
  74. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do { \
  75. if(LOGGER) LOGGER(UA_LOGLEVEL_WARNING, CATEGORY, __VA_ARGS__); } while(0)
  76. #else
  77. #define UA_LOG_WARNING(LOGGER, CATEGORY, ...) do {} while(0)
  78. #endif
  79. #if UA_LOGLEVEL <= 500
  80. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do { \
  81. if(LOGGER) LOGGER(UA_LOGLEVEL_ERROR, CATEGORY, __VA_ARGS__); } while(0)
  82. #else
  83. #define UA_LOG_ERROR(LOGGER, CATEGORY, ...) do {} while(0)
  84. #endif
  85. #if UA_LOGLEVEL <= 600
  86. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do { \
  87. if(LOGGER) LOGGER(UA_LOGLEVEL_FATAL, CATEGORY, __VA_ARGS__); } while(0)
  88. #else
  89. #define UA_LOG_FATAL(LOGGER, CATEGORY, ...) do {} while(0)
  90. #endif
  91. #ifdef __cplusplus
  92. } // extern "C"
  93. #endif
  94. #endif /* UA_LOG_H_ */