mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: log/applet: add new function syslog_applet_append_event()
This function takes a buffer on input, and offset and a length, and consumes the block from that buffer to send it to the appctx's output buffer. Contrary to its sibling applet_append_line(), instead of just appending an LF at the end of the line, it prepends the message size in decimal and a space before the message, as expected by syslog TCP implementaions. This will be used to simplify the ring reader code.
This commit is contained in:
parent
6ae41dc510
commit
201c706330
@ -87,6 +87,8 @@ void app_log(struct list *loggers, struct buffer *tag, int level, const char *fo
|
|||||||
*/
|
*/
|
||||||
int add_to_logformat_list(char *start, char *end, int type, struct list *list_format, char **err);
|
int add_to_logformat_list(char *start, char *end, int type, struct list *list_format, char **err);
|
||||||
|
|
||||||
|
ssize_t syslog_applet_append_event(void *ctx, const struct buffer *buf, size_t ofs, size_t len);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the log_format string and fill a linked list.
|
* Parse the log_format string and fill a linked list.
|
||||||
* Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
|
* Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
|
||||||
|
35
src/log.c
35
src/log.c
@ -4345,6 +4345,41 @@ static struct applet syslog_applet = {
|
|||||||
.release = NULL,
|
.release = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Atomically append an event to applet >ctx>'s output, prepending it with its
|
||||||
|
* size in decimal followed by a space.
|
||||||
|
* The line is read from <buf> at offset <ofs> relative to the buffer's head,
|
||||||
|
* for <len> bytes. It returns the number of bytes consumed from the input
|
||||||
|
* buffer on success, -1 if it temporarily cannot (buffer full), -2 if it will
|
||||||
|
* never be able to (too large msg). The input buffer is not modified. The
|
||||||
|
* caller is responsible for making sure that there are at least ofs+len bytes
|
||||||
|
* in the input buffer.
|
||||||
|
*/
|
||||||
|
ssize_t syslog_applet_append_event(void *ctx, const struct buffer *buf, size_t ofs, size_t len)
|
||||||
|
{
|
||||||
|
struct appctx *appctx = ctx;
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
/* first, encode the message's size */
|
||||||
|
chunk_reset(&trash);
|
||||||
|
p = ulltoa(len, trash.area, b_size(&trash));
|
||||||
|
if (p) {
|
||||||
|
trash.data = p - trash.area;
|
||||||
|
trash.area[trash.data++] = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check if the message has a chance to fit */
|
||||||
|
if (unlikely(!p || trash.data + len > b_size(&trash)))
|
||||||
|
return -2;
|
||||||
|
|
||||||
|
/* try to transfer it or report full */
|
||||||
|
trash.data += b_getblk(buf, trash.area + trash.data, len, ofs);
|
||||||
|
if (applet_putchk(appctx, &trash) == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* OK done */
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse "log-forward" section and create corresponding sink buffer.
|
* Parse "log-forward" section and create corresponding sink buffer.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user