1 /* 2 include/proto/log.h 3 This file contains definitions of log-related functions, structures, 4 and macros. 5 6 Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu 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 29 #include <common/config.h> 30 #include <common/memory.h> 31 #include <common/hathreads.h> 32 33 #include <types/log.h> 34 #include <types/proxy.h> 35 #include <types/stream.h> 36 37 extern struct pool_head *pool_head_requri; 38 extern struct pool_head *pool_head_uniqueid; 39 40 extern char *log_format; 41 extern char default_tcp_log_format[]; 42 extern char default_http_log_format[]; 43 extern char clf_http_log_format[]; 44 45 extern char default_rfc5424_sd_log_format[]; 46 47 extern THREAD_LOCAL char *logheader; 48 extern THREAD_LOCAL char *logheader_rfc5424; 49 extern THREAD_LOCAL char *logline; 50 extern THREAD_LOCAL char *logline_rfc5424; 51 52 53 /* 54 * Initializes some log data. 55 */ 56 void init_log(); 57 58 59 /* Initialize/Deinitialize log buffers used for syslog messages */ 60 int init_log_buffers(); 61 void deinit_log_buffers(); 62 63 /* 64 * Builds a log line. 65 */ 66 int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list_format); 67 68 /* 69 * send a log for the stream when we have enough info about it. 70 * Will not log if the frontend has no log defined. 71 */ 72 void strm_log(struct stream *s); 73 74 /* 75 * add to the logformat linked list 76 */ 77 int add_to_logformat_list(char *start, char *end, int type, struct list *list_format, char **err); 78 79 /* 80 * Parse the log_format string and fill a linked list. 81 * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname 82 * You can set arguments using { } : %{many arguments}varname 83 */ 84 int parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap, char **err); 85 /* 86 * Displays the message on stderr with the date and pid. Overrides the quiet 87 * mode during startup. 88 */ 89 void ha_alert(const char *fmt, ...) 90 __attribute__ ((format(printf, 1, 2))); 91 92 /* 93 * Displays the message on stderr with the date and pid. 94 */ 95 void ha_warning(const char *fmt, ...) 96 __attribute__ ((format(printf, 1, 2))); 97 98 /* 99 * Displays the message on <out> only if quiet mode is not set. 100 */ 101 void qfprintf(FILE *out, const char *fmt, ...) 102 __attribute__ ((format(printf, 2, 3))); 103 104 /* 105 * This function adds a header to the message and sends the syslog message 106 * using a printf format string 107 */ 108 void send_log(struct proxy *p, int level, const char *format, ...) 109 __attribute__ ((format(printf, 3, 4))); 110 111 /* 112 * This function sends a syslog message to both log servers of a proxy, 113 * or to global log servers if the proxy is NULL. 114 * It also tries not to waste too much time computing the message header. 115 * It doesn't care about errors nor does it report them. 116 */ 117 118 void __send_log(struct proxy *p, int level, char *message, size_t size, char *sd, size_t sd_size); 119 120 /* 121 * returns log format for <fmt> or -1 if not found. 122 */ 123 int get_log_format(const char *fmt); 124 125 /* 126 * returns log level for <lev> or -1 if not found. 127 */ 128 int get_log_level(const char *lev); 129 130 /* 131 * returns log facility for <fac> or -1 if not found. 132 */ 133 int get_log_facility(const char *fac); 134 135 /* 136 * Write a string in the log string 137 * Take cares of quote options 138 * 139 * Return the adress of the \0 character, or NULL on error 140 */ 141 char *lf_text_len(char *dst, const char *src, size_t len, size_t size, struct logformat_node *node); 142 143 /* 144 * Write a IP adress to the log string 145 * +X option write in hexadecimal notation, most signifant byte on the left 146 */ 147 char *lf_ip(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node); 148 149 /* 150 * Write a port to the log 151 * +X option write in hexadecimal notation, most signifant byte on the left 152 */ 153 char *lf_port(char *dst, struct sockaddr *sockaddr, size_t size, struct logformat_node *node); 154 155 156 #endif /* _PROTO_LOG_H */ 157 158 /* 159 * Local variables: 160 * c-indent-level: 8 161 * c-basic-offset: 8 162 * End: 163 */ 164