• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 struct Curl_easy;
28 struct Curl_cfilter;
29 
30 /**
31  * Init logging, return != 0 on failure.
32  */
33 CURLcode Curl_log_init(void);
34 
35 
36 void Curl_infof(struct Curl_easy *, const char *fmt, ...);
37 void Curl_failf(struct Curl_easy *, const char *fmt, ...);
38 
39 #if defined(CURL_DISABLE_VERBOSE_STRINGS)
40 
41 #if defined(HAVE_VARIADIC_MACROS_C99)
42 #define infof(...)  Curl_nop_stmt
43 #elif defined(HAVE_VARIADIC_MACROS_GCC)
44 #define infof(x...)  Curl_nop_stmt
45 #else
46 #error "missing VARIADIC macro define, fix and rebuild!"
47 #endif
48 
49 #else /* CURL_DISABLE_VERBOSE_STRINGS */
50 
51 #define infof Curl_infof
52 
53 #endif /* CURL_DISABLE_VERBOSE_STRINGS */
54 
55 #define failf Curl_failf
56 
57 
58 #define CURL_LOG_DEFAULT  0
59 #define CURL_LOG_DEBUG    1
60 #define CURL_LOG_TRACE    2
61 
62 
63 /* the function used to output verbose information */
64 void Curl_debug(struct Curl_easy *data, curl_infotype type,
65                 char *ptr, size_t size);
66 
67 #ifdef DEBUGBUILD
68 
69 /* explainer: we have some mix configuration and werror settings
70  * that define HAVE_VARIADIC_MACROS_C99 even though C89 is enforced
71  * on gnuc and some other compiler. Need to treat carefully.
72  */
73 #if defined(HAVE_VARIADIC_MACROS_C99) && \
74     defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
75 
76 #define LOG_CF(data, cf, ...) \
77   do { if(Curl_log_cf_is_debug(cf)) \
78          Curl_log_cf_debug(data, cf, __VA_ARGS__); } while(0)
79 #else
80 #define LOG_CF Curl_log_cf_debug
81 #endif
82 
83 void Curl_log_cf_debug(struct Curl_easy *data, struct Curl_cfilter *cf,
84 #if defined(__GNUC__) && !defined(printf) &&                    \
85   defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
86   !defined(__MINGW32__)
87                        const char *fmt, ...)
88                        __attribute__((format(printf, 3, 4)));
89 #else
90                        const char *fmt, ...);
91 #endif
92 
93 #define Curl_log_cf_is_debug(cf) \
94     ((cf) && (cf)->cft->log_level >= CURL_LOG_DEBUG)
95 
96 #else /* !DEBUGBUILD */
97 
98 #if defined(HAVE_VARIADIC_MACROS_C99) && \
99     defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
100 #define LOG_CF(...)               Curl_nop_stmt
101 #define Curl_log_cf_debug(...)    Curl_nop_stmt
102 #elif defined(HAVE_VARIADIC_MACROS_GCC) && \
103     defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
104 #define LOG_CF(x...)              Curl_nop_stmt
105 #define Curl_log_cf_debug(x...)   Curl_nop_stmt
106 #else
107 #define LOG_CF                    Curl_log_cf_debug
108 /* without c99, we seem unable to completely define away this function. */
109 void Curl_log_cf_debug(struct Curl_easy *data, struct Curl_cfilter *cf,
110                        const char *fmt, ...);
111 #endif
112 
113 #define Curl_log_cf_is_debug(x)   ((void)(x), FALSE)
114 
115 #endif  /* !DEBUGBUILD */
116 
117 #define LOG_CF_IS_DEBUG(x)        Curl_log_cf_is_debug(x)
118 
119 /* Macros intended for DEBUGF logging, use like:
120  * DEBUGF(infof(data, CFMSG(cf, "this filter %s rocks"), "very much"));
121  * and it will output:
122  * [CONN-1-0][CF-SSL] this filter very much rocks
123  * on connection #1 with sockindex 0 for filter of type "SSL". */
124 #define DMSG(d,msg)  \
125   "[CONN-%ld] "msg, (d)->conn->connection_id
126 #define DMSGI(d,i,msg)  \
127   "[CONN-%ld-%d] "msg, (d)->conn->connection_id, (i)
128 #define CMSG(c,msg)  \
129   "[CONN-%ld] "msg, (c)->connection_id
130 #define CMSGI(c,i,msg)  \
131   "[CONN-%ld-%d] "msg, (c)->connection_id, (i)
132 #define CFMSG(cf,msg)  \
133   "[CONN-%ld-%d][CF-%s] "msg, (cf)->conn->connection_id, \
134   (cf)->sockindex, (cf)->cft->name
135 
136 
137 
138 #endif /* HEADER_CURL_LOG_H */
139