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> |
| 33 | #include <types/session.h> |
| 34 | |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 35 | extern struct pool_head *pool2_requri; |
| 36 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 37 | extern char *log_format; |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 38 | extern char default_tcp_log_format[]; |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 39 | extern char default_http_log_format[]; |
| 40 | extern char clf_http_log_format[]; |
| 41 | |
William Lallemand | bddd4fd | 2012-02-27 11:23:10 +0100 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * send a log for the session when we have enough info about it. |
| 45 | * Will not log if the frontend has no log defined. |
| 46 | */ |
| 47 | void sess_log(struct session *s); |
| 48 | |
William Lallemand | 723b73a | 2012-02-08 16:37:49 +0100 | [diff] [blame] | 49 | /* |
| 50 | * Parse args in a logformat_var |
| 51 | */ |
| 52 | int parse_logformat_var_args(char *args, struct logformat_node *node); |
| 53 | |
| 54 | /* |
| 55 | * Parse a variable '%varname' or '%{args}varname' in logformat |
| 56 | * |
| 57 | */ |
| 58 | int parse_logformat_var(char *str, size_t len, struct proxy *curproxy); |
| 59 | |
| 60 | /* |
| 61 | * add to the logformat linked list |
| 62 | */ |
| 63 | void add_to_logformat_list(char *start, char *end, int type, struct proxy *curproxy); |
| 64 | |
| 65 | /* |
| 66 | * Parse the log_format string and fill a linked list. |
| 67 | * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname |
| 68 | * You can set arguments using { } : %{many arguments}varname |
| 69 | */ |
| 70 | void parse_logformat_string(char *str, struct proxy *curproxy); |
| 71 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 72 | /* |
| 73 | * Displays the message on stderr with the date and pid. Overrides the quiet |
| 74 | * mode during startup. |
| 75 | */ |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 76 | void Alert(const char *fmt, ...) |
| 77 | __attribute__ ((format(printf, 1, 2))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Displays the message on stderr with the date and pid. |
| 81 | */ |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 82 | void Warning(const char *fmt, ...) |
| 83 | __attribute__ ((format(printf, 1, 2))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Displays the message on <out> only if quiet mode is not set. |
| 87 | */ |
Willy Tarreau | 40d2516 | 2009-04-03 12:01:47 +0200 | [diff] [blame] | 88 | void qfprintf(FILE *out, const char *fmt, ...) |
| 89 | __attribute__ ((format(printf, 2, 3))); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 90 | |
William Lallemand | 2a4a44f | 2012-02-06 16:00:33 +0100 | [diff] [blame] | 91 | /* generate the syslog header one time per second */ |
| 92 | char *hdr_log(char *dst); |
| 93 | |
| 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 |
| 122 | * Take cares of mandatory and quote options |
| 123 | * |
| 124 | * Return the adress of the \0 character, or NULL on error |
| 125 | */ |
| 126 | char *logformat_write_string(char *dst, char *src, size_t size, struct logformat_node *node); |
| 127 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 128 | #endif /* _PROTO_LOG_H */ |
| 129 | |
| 130 | /* |
| 131 | * Local variables: |
| 132 | * c-indent-level: 8 |
| 133 | * c-basic-offset: 8 |
| 134 | * End: |
| 135 | */ |