Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/proto/log.h |
| 3 | This file contains definitions of log-related functions, structures, |
| 4 | and macros. |
| 5 | |
Willy Tarreau | ec6c5df | 2008-07-15 00:22:45 +0200 | [diff] [blame] | 6 | Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 7 | |
| 8 | This library is free software; you can redistribute it and/or |
| 9 | modify it under the terms of the GNU Lesser General Public |
| 10 | License as published by the Free Software Foundation, version 2.1 |
| 11 | exclusively. |
| 12 | |
| 13 | This library is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | Lesser General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU Lesser General Public |
| 19 | License along with this library; if not, write to the Free Software |
| 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #ifndef _PROTO_LOG_H |
| 24 | #define _PROTO_LOG_H |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <syslog.h> |
| 28 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 29 | #include <common/config.h> |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 30 | #include <common/memory.h> |
Christopher Faulet | f8188c6 | 2017-06-02 16:20:16 +0200 | [diff] [blame] | 31 | #include <common/hathreads.h> |
| 32 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | #include <types/log.h> |
| 34 | #include <types/proxy.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 35 | #include <types/stream.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 36 | |
Willy Tarreau | 43c538e | 2018-09-05 14:58:15 +0200 | [diff] [blame] | 37 | #include <proto/stream.h> |
| 38 | |
Willy Tarreau | bafbe01 | 2017-11-24 17:34:44 +0100 | [diff] [blame] | 39 | extern struct pool_head *pool_head_requri; |
| 40 | extern struct pool_head *pool_head_uniqueid; |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 41 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 42 | extern char *log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 43 | extern char default_tcp_log_format[]; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 44 | extern char default_http_log_format[]; |
| 45 | extern char clf_http_log_format[]; |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 46 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 47 | extern char default_rfc5424_sd_log_format[]; |
| 48 | |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 49 | extern unsigned int dropped_logs; |
| 50 | |
Christopher Faulet | f8188c6 | 2017-06-02 16:20:16 +0200 | [diff] [blame] | 51 | extern THREAD_LOCAL char *logheader; |
| 52 | extern THREAD_LOCAL char *logheader_rfc5424; |
| 53 | extern THREAD_LOCAL char *logline; |
| 54 | extern THREAD_LOCAL char *logline_rfc5424; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 55 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 56 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 57 | /* |
| 58 | * Initializes some log data. |
| 59 | */ |
| 60 | void init_log(); |
| 61 | |
Christopher Faulet | 0132d06 | 2017-07-26 15:33:35 +0200 | [diff] [blame] | 62 | |
| 63 | /* Initialize/Deinitialize log buffers used for syslog messages */ |
| 64 | int init_log_buffers(); |
| 65 | void deinit_log_buffers(); |
| 66 | |
Dragan Dosen | 835b921 | 2016-02-12 13:23:03 +0100 | [diff] [blame] | 67 | /* |
| 68 | * Builds a log line. |
| 69 | */ |
Willy Tarreau | 43c538e | 2018-09-05 14:58:15 +0200 | [diff] [blame] | 70 | int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t maxsize, struct list *list_format); |
| 71 | |
| 72 | static inline int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list_format) |
| 73 | { |
| 74 | return sess_build_logline(strm_sess(s), s, dst, maxsize, list_format); |
| 75 | } |
| 76 | |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 77 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 78 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 79 | * send a log for the stream when we have enough info about it. |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 80 | * Will not log if the frontend has no log defined. |
| 81 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 82 | void strm_log(struct stream *s); |
Willy Tarreau | 5383935 | 2018-09-05 19:51:10 +0200 | [diff] [blame] | 83 | void sess_log(struct session *sess); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 84 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 85 | /* |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 86 | * add to the logformat linked list |
| 87 | */ |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 88 | int add_to_logformat_list(char *start, char *end, int type, struct list *list_format, char **err); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Parse the log_format string and fill a linked list. |
| 92 | * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname |
| 93 | * You can set arguments using { } : %{many arguments}varname |
| 94 | */ |
Thierry FOURNIER / OZON.IO | 8a4e442 | 2016-11-23 00:41:28 +0100 | [diff] [blame] | 95 | int parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, char **err); |
Christopher Faulet | 4b0b79d | 2018-03-26 15:54:32 +0200 | [diff] [blame] | 96 | |
| 97 | /* Parse "log" keyword and update the linked list. */ |
| 98 | int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err); |
| 99 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 100 | /* |
| 101 | * Displays the message on stderr with the date and pid. Overrides the quiet |
| 102 | * mode during startup. |
| 103 | */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 104 | void ha_alert(const char *fmt, ...) |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 105 | __attribute__ ((format(printf, 1, 2))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Displays the message on stderr with the date and pid. |
| 109 | */ |
Christopher Faulet | 767a84b | 2017-11-24 16:50:31 +0100 | [diff] [blame] | 110 | void ha_warning(const char *fmt, ...) |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 111 | __attribute__ ((format(printf, 1, 2))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Displays the message on <out> only if quiet mode is not set. |
| 115 | */ |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 116 | void qfprintf(FILE *out, const char *fmt, ...) |
| 117 | __attribute__ ((format(printf, 2, 3))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 118 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 119 | /* |
| 120 | * This function adds a header to the message and sends the syslog message |
| 121 | * using a printf format string |
| 122 | */ |
| 123 | void send_log(struct proxy *p, int level, const char *format, ...) |
| 124 | __attribute__ ((format(printf, 3, 4))); |
| 125 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 126 | /* |
| 127 | * This function sends a syslog message to both log servers of a proxy, |
| 128 | * or to global log servers if the proxy is NULL. |
| 129 | * It also tries not to waste too much time computing the message header. |
| 130 | * It doesn't care about errors nor does it report them. |
| 131 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 132 | |
Dragan Dosen | 0b85ece | 2015-09-25 19:17:44 +0200 | [diff] [blame] | 133 | void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd, size_t sd_size); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 134 | |
| 135 | /* |
Dragan Dosen | 1322d09 | 2015-09-22 16:05:32 +0200 | [diff] [blame] | 136 | * returns log format for <fmt> or -1 if not found. |
| 137 | */ |
| 138 | int get_log_format(const char *fmt); |
| 139 | |
| 140 | /* |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 141 | * returns log level for <lev> or -1 if not found. |
| 142 | */ |
| 143 | int get_log_level(const char *lev); |
| 144 | |
| 145 | /* |
| 146 | * returns log facility for <fac> or -1 if not found. |
| 147 | */ |
| 148 | int get_log_facility(const char *fac); |
| 149 | |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 150 | /* |
| 151 | * Write a string in the log string |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 152 | * Take cares of quote options |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 153 | * |
| 154 | * Return the adress of the \0 character, or NULL on error |
| 155 | */ |
Olivier Houchard | 5462052 | 2018-09-06 18:14:09 +0200 | [diff] [blame] | 156 | char *lf_text_len(char *dst, const char *src, size_t len, size_t size, const struct logformat_node *node); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Write a IP adress to the log string |
| 160 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 161 | */ |
Willy Tarreau | 26ffa85 | 2018-09-05 15:23:10 +0200 | [diff] [blame] | 162 | char *lf_ip(char *dst, const struct sockaddr *sockaddr, size_t size, const struct logformat_node *node); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Write a port to the log |
| 166 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 167 | */ |
Willy Tarreau | 26ffa85 | 2018-09-05 15:23:10 +0200 | [diff] [blame] | 168 | char *lf_port(char *dst, const struct sockaddr *sockaddr, size_t size, const struct logformat_node *node); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 169 | |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 170 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 171 | #endif /* _PROTO_LOG_H */ |
| 172 | |
| 173 | /* |
| 174 | * Local variables: |
| 175 | * c-indent-level: 8 |
| 176 | * c-basic-offset: 8 |
| 177 | * End: |
| 178 | */ |