2
0

curl_log.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #ifndef HEADER_CURL_LOG_H
  2. #define HEADER_CURL_LOG_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. struct Curl_easy;
  27. struct Curl_cfilter;
  28. /**
  29. * Init logging, return != 0 on failure.
  30. */
  31. CURLcode Curl_log_init(void);
  32. void Curl_infof(struct Curl_easy *, const char *fmt, ...);
  33. void Curl_failf(struct Curl_easy *, const char *fmt, ...);
  34. #if defined(CURL_DISABLE_VERBOSE_STRINGS)
  35. #if defined(HAVE_VARIADIC_MACROS_C99)
  36. #define infof(...) Curl_nop_stmt
  37. #elif defined(HAVE_VARIADIC_MACROS_GCC)
  38. #define infof(x...) Curl_nop_stmt
  39. #else
  40. #error "missing VARIADIC macro define, fix and rebuild!"
  41. #endif
  42. #else /* CURL_DISABLE_VERBOSE_STRINGS */
  43. #define infof Curl_infof
  44. #endif /* CURL_DISABLE_VERBOSE_STRINGS */
  45. #define failf Curl_failf
  46. #define CURL_LOG_DEFAULT 0
  47. #define CURL_LOG_DEBUG 1
  48. #define CURL_LOG_TRACE 2
  49. /* the function used to output verbose information */
  50. void Curl_debug(struct Curl_easy *data, curl_infotype type,
  51. char *ptr, size_t size);
  52. #ifdef DEBUGBUILD
  53. /* explainer: we have some mix configuration and werror settings
  54. * that define HAVE_VARIADIC_MACROS_C99 even though C89 is enforced
  55. * on gnuc and some other compiler. Need to treat carefully.
  56. */
  57. #if defined(HAVE_VARIADIC_MACROS_C99) && \
  58. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  59. #define LOG_CF(data, cf, ...) \
  60. do { if(Curl_log_cf_is_debug(cf)) \
  61. Curl_log_cf_debug(data, cf, __VA_ARGS__); } while(0)
  62. #else
  63. #define LOG_CF Curl_log_cf_debug
  64. #endif
  65. void Curl_log_cf_debug(struct Curl_easy *data, struct Curl_cfilter *cf,
  66. #if defined(__GNUC__) && !defined(printf) && \
  67. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  68. !defined(__MINGW32__)
  69. const char *fmt, ...)
  70. __attribute__((format(printf, 3, 4)));
  71. #else
  72. const char *fmt, ...);
  73. #endif
  74. #define Curl_log_cf_is_debug(cf) \
  75. ((cf) && (cf)->cft->log_level >= CURL_LOG_DEBUG)
  76. #else /* !DEBUGBUILD */
  77. #if defined(HAVE_VARIADIC_MACROS_C99) && \
  78. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  79. #define LOG_CF(...) Curl_nop_stmt
  80. #define Curl_log_cf_debug(...) Curl_nop_stmt
  81. #elif defined(HAVE_VARIADIC_MACROS_GCC) && \
  82. defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
  83. #define LOG_CF(x...) Curl_nop_stmt
  84. #define Curl_log_cf_debug(x...) Curl_nop_stmt
  85. #else
  86. #define LOG_CF Curl_log_cf_debug
  87. /* without c99, we seem unable to completely define away this function. */
  88. void Curl_log_cf_debug(struct Curl_easy *data, struct Curl_cfilter *cf,
  89. const char *fmt, ...);
  90. #endif
  91. #define Curl_log_cf_is_debug(x) ((void)(x), FALSE)
  92. #endif /* !DEBUGBUILD */
  93. #define LOG_CF_IS_DEBUG(x) Curl_log_cf_is_debug(x)
  94. /* Macros intended for DEBUGF logging, use like:
  95. * DEBUGF(infof(data, CFMSG(cf, "this filter %s rocks"), "very much"));
  96. * and it will output:
  97. * [CONN-1-0][CF-SSL] this filter very much rocks
  98. * on connection #1 with sockindex 0 for filter of type "SSL". */
  99. #define DMSG(d,msg) \
  100. "[CONN-%ld] "msg, (d)->conn->connection_id
  101. #define DMSGI(d,i,msg) \
  102. "[CONN-%ld-%d] "msg, (d)->conn->connection_id, (i)
  103. #define CMSG(c,msg) \
  104. "[CONN-%ld] "msg, (c)->connection_id
  105. #define CMSGI(c,i,msg) \
  106. "[CONN-%ld-%d] "msg, (c)->connection_id, (i)
  107. #define CFMSG(cf,msg) \
  108. "[CONN-%ld-%d][CF-%s] "msg, (cf)->conn->connection_id, \
  109. (cf)->sockindex, (cf)->cft->name
  110. #endif /* HEADER_CURL_LOG_H */