summaryrefslogtreecommitdiff
path: root/lib/curl_log.h
blob: ad6143fa991c3d22b32617ccfbe0c5132db38424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef HEADER_CURL_LOG_H
#define HEADER_CURL_LOG_H
/***************************************************************************
 *                                  _   _ ____  _
 *  Project                     ___| | | |  _ \| |
 *                             / __| | | | |_) | |
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
 * are also available at https://curl.se/docs/copyright.html.
 *
 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
 * copies of the Software, and permit persons to whom the Software is
 * furnished to do so, under the terms of the COPYING file.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 * SPDX-License-Identifier: curl
 *
 ***************************************************************************/

struct Curl_easy;
struct Curl_cfilter;

/**
 * Init logging, return != 0 on failure.
 */
CURLcode Curl_log_init(void);


void Curl_infof(struct Curl_easy *, const char *fmt, ...);
void Curl_failf(struct Curl_easy *, const char *fmt, ...);

#if defined(CURL_DISABLE_VERBOSE_STRINGS)

#if defined(HAVE_VARIADIC_MACROS_C99)
#define infof(...)  Curl_nop_stmt
#elif defined(HAVE_VARIADIC_MACROS_GCC)
#define infof(x...)  Curl_nop_stmt
#else
#error "missing VARIADIC macro define, fix and rebuild!"
#endif

#else /* CURL_DISABLE_VERBOSE_STRINGS */

#define infof Curl_infof

#endif /* CURL_DISABLE_VERBOSE_STRINGS */

#define failf Curl_failf


#define CURL_LOG_DEFAULT  0
#define CURL_LOG_DEBUG    1
#define CURL_LOG_TRACE    2


/* the function used to output verbose information */
void Curl_debug(struct Curl_easy *data, curl_infotype type,
                char *ptr, size_t size);

#ifdef DEBUGBUILD

/* explainer: we have some mix configuration and werror settings
 * that define HAVE_VARIADIC_MACROS_C99 even though C89 is enforced
 * on gnuc and some other compiler. Need to treat carefully.
 */
#if defined(HAVE_VARIADIC_MACROS_C99) && \
    defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)

#define LOG_CF(data, cf, ...) \
  do { if(Curl_log_cf_is_debug(cf)) \
         Curl_log_cf_debug(data, cf, __VA_ARGS__); } while(0)
#else
#define LOG_CF Curl_log_cf_debug
#endif

void Curl_log_cf_debug(struct Curl_easy *data, struct Curl_cfilter *cf,
#if defined(__GNUC__) && !defined(printf) &&                    \
  defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  !defined(__MINGW32__)
                       const char *fmt, ...)
                       __attribute__((format(printf, 3, 4)));
#else
                       const char *fmt, ...);
#endif

#define Curl_log_cf_is_debug(cf) \
    ((cf) && (cf)->cft->log_level >= CURL_LOG_DEBUG)

#else /* !DEBUGBUILD */

#if defined(HAVE_VARIADIC_MACROS_C99) && \
    defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define LOG_CF(...)               Curl_nop_stmt
#define Curl_log_cf_debug(...)    Curl_nop_stmt
#elif defined(HAVE_VARIADIC_MACROS_GCC) && \
    defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define LOG_CF(x...)              Curl_nop_stmt
#define Curl_log_cf_debug(x...)   Curl_nop_stmt
#else
#define LOG_CF                    Curl_log_cf_debug
/* without c99, we seem unable to completely define away this function. */
void Curl_log_cf_debug(struct Curl_easy *data, struct Curl_cfilter *cf,
                       const char *fmt, ...);
#endif

#define Curl_log_cf_is_debug(x)   ((void)(x), FALSE)

#endif  /* !DEBUGBUILD */

#define LOG_CF_IS_DEBUG(x)        Curl_log_cf_is_debug(x)

/* Macros intended for DEBUGF logging, use like:
 * DEBUGF(infof(data, CFMSG(cf, "this filter %s rocks"), "very much"));
 * and it will output:
 * [CONN-1-0][CF-SSL] this filter very much rocks
 * on connection #1 with sockindex 0 for filter of type "SSL". */
#define DMSG(d,msg)  \
  "[CONN-%ld] "msg, (d)->conn->connection_id
#define DMSGI(d,i,msg)  \
  "[CONN-%ld-%d] "msg, (d)->conn->connection_id, (i)
#define CMSG(c,msg)  \
  "[CONN-%ld] "msg, (c)->connection_id
#define CMSGI(c,i,msg)  \
  "[CONN-%ld-%d] "msg, (c)->connection_id, (i)
#define CFMSG(cf,msg)  \
  "[CONN-%ld-%d][CF-%s] "msg, (cf)->conn->connection_id, \
  (cf)->sockindex, (cf)->cft->name



#endif /* HEADER_CURL_LOG_H */