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> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | #include <types/log.h> |
| 32 | #include <types/proxy.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 33 | #include <types/stream.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 35 | extern struct pool_head *pool2_requri; |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 36 | extern struct pool_head *pool2_uniqueid; |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 37 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 38 | extern char *log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 39 | extern char default_tcp_log_format[]; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 40 | extern char default_http_log_format[]; |
| 41 | extern char clf_http_log_format[]; |
Willy Tarreau | 18324f5 | 2014-06-27 18:10:07 +0200 | [diff] [blame] | 42 | extern char *logline; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 43 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 44 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 45 | int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list_format); |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 46 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 47 | /* |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 48 | * 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] | 49 | * Will not log if the frontend has no log defined. |
| 50 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 51 | void strm_log(struct stream *s); |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 52 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 53 | /* |
| 54 | * Parse args in a logformat_var |
| 55 | */ |
| 56 | int parse_logformat_var_args(char *args, struct logformat_node *node); |
| 57 | |
| 58 | /* |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 59 | * Parse a variable '%varname' or '%{args}varname' in log-format |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 60 | * |
| 61 | */ |
Willy Tarreau | 8a3f52f | 2012-12-20 21:23:42 +0100 | [diff] [blame] | 62 | int parse_logformat_var(char *arg, int arg_len, char *var, int var_len, struct proxy *curproxy, struct list *list_format, int *defoptions); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * add to the logformat linked list |
| 66 | */ |
William Lallemand | 1d70556 | 2012-03-12 12:46:41 +0100 | [diff] [blame] | 67 | void add_to_logformat_list(char *start, char *end, int type, struct list *list_format); |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Parse the log_format string and fill a linked list. |
| 71 | * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname |
| 72 | * You can set arguments using { } : %{many arguments}varname |
| 73 | */ |
Thierry FOURNIER | eeaa951 | 2014-02-11 14:00:19 +0100 | [diff] [blame] | 74 | void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, const char *file, int line); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | /* |
| 76 | * Displays the message on stderr with the date and pid. Overrides the quiet |
| 77 | * mode during startup. |
| 78 | */ |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 79 | void Alert(const char *fmt, ...) |
| 80 | __attribute__ ((format(printf, 1, 2))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Displays the message on stderr with the date and pid. |
| 84 | */ |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 85 | void Warning(const char *fmt, ...) |
| 86 | __attribute__ ((format(printf, 1, 2))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Displays the message on <out> only if quiet mode is not set. |
| 90 | */ |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 91 | void qfprintf(FILE *out, const char *fmt, ...) |
| 92 | __attribute__ ((format(printf, 2, 3))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 93 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 94 | /* |
| 95 | * This function adds a header to the message and sends the syslog message |
| 96 | * using a printf format string |
| 97 | */ |
| 98 | void send_log(struct proxy *p, int level, const char *format, ...) |
| 99 | __attribute__ ((format(printf, 3, 4))); |
| 100 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 101 | /* |
| 102 | * This function sends a syslog message to both log servers of a proxy, |
| 103 | * or to global log servers if the proxy is NULL. |
| 104 | * It also tries not to waste too much time computing the message header. |
| 105 | * It doesn't care about errors nor does it report them. |
| 106 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 107 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 108 | void __send_log(struct proxy *p, int level, char *message, size_t size); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 109 | |
| 110 | /* |
| 111 | * returns log level for <lev> or -1 if not found. |
| 112 | */ |
| 113 | int get_log_level(const char *lev); |
| 114 | |
| 115 | /* |
| 116 | * returns log facility for <fac> or -1 if not found. |
| 117 | */ |
| 118 | int get_log_facility(const char *fac); |
| 119 | |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 120 | /* |
| 121 | * Write a string in the log string |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 122 | * Take cares of quote options |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 123 | * |
| 124 | * Return the adress of the \0 character, or NULL on error |
| 125 | */ |
Willy Tarreau | 2b0108a | 2012-12-21 19:23:44 +0100 | [diff] [blame] | 126 | char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct logformat_node *node); |
William Lallemand | 5f23240 | 2012-04-05 18:02:55 +0200 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * Write a IP adress to the log string |
| 130 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 131 | */ |
| 132 | char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node); |
| 133 | |
| 134 | /* |
| 135 | * Write a port to the log |
| 136 | * +X option write in hexadecimal notation, most signifant byte on the left |
| 137 | */ |
| 138 | char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node); |
| 139 | |
William Lallemand | a1cc381 | 2012-02-08 16:38:44 +0100 | [diff] [blame] | 140 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 141 | #endif /* _PROTO_LOG_H */ |
| 142 | |
| 143 | /* |
| 144 | * Local variables: |
| 145 | * c-indent-level: 8 |
| 146 | * c-basic-offset: 8 |
| 147 | * End: |
| 148 | */ |