mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: log: provide a function to emit a log for a session
The new function sess_log() only needs a session to emit a log. It will ignore the parts that depend on the stream. It is usable to emit a log to report early errors in muxes. These ones will typically mention "<BADREQ>" for the request and 0 for the HTTP status code.
This commit is contained in:
parent
09bb27cdea
commit
5383935856
@ -78,6 +78,7 @@ static inline int build_logline(struct stream *s, char *dst, size_t maxsize, str
|
|||||||
* Will not log if the frontend has no log defined.
|
* Will not log if the frontend has no log defined.
|
||||||
*/
|
*/
|
||||||
void strm_log(struct stream *s);
|
void strm_log(struct stream *s);
|
||||||
|
void sess_log(struct session *sess);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* add to the logformat linked list
|
* add to the logformat linked list
|
||||||
|
33
src/log.c
33
src/log.c
@ -2620,6 +2620,39 @@ void strm_log(struct stream *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* send a minimalist log for the session. Will not log if the frontend has no
|
||||||
|
* log defined. It is assumed that this is only used to report anomalies that
|
||||||
|
* cannot lead to the creation of a regular stream. Because of this the log
|
||||||
|
* level is LOG_INFO or LOG_ERR depending on the "log-separate-error" setting
|
||||||
|
* in the frontend. The caller must simply know that it should not call this
|
||||||
|
* function to report unimportant events.
|
||||||
|
*/
|
||||||
|
void sess_log(struct session *sess)
|
||||||
|
{
|
||||||
|
int size, level;
|
||||||
|
int sd_size = 0;
|
||||||
|
|
||||||
|
if (LIST_ISEMPTY(&sess->fe->logsrvs))
|
||||||
|
return;
|
||||||
|
|
||||||
|
level = LOG_INFO;
|
||||||
|
if (sess->fe->options2 & PR_O2_LOGERRORS)
|
||||||
|
level = LOG_ERR;
|
||||||
|
|
||||||
|
if (!LIST_ISEMPTY(&sess->fe->logformat_sd)) {
|
||||||
|
sd_size = sess_build_logline(sess, NULL,
|
||||||
|
logline_rfc5424, global.max_syslog_len,
|
||||||
|
&sess->fe->logformat_sd);
|
||||||
|
}
|
||||||
|
|
||||||
|
size = sess_build_logline(sess, NULL, logline, global.max_syslog_len, &sess->fe->logformat);
|
||||||
|
if (size > 0) {
|
||||||
|
HA_ATOMIC_ADD(&sess->fe->log_count, 1);
|
||||||
|
__send_log(sess->fe, level, logline, size + 1, logline_rfc5424, sd_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int cli_io_handler_show_startup_logs(struct appctx *appctx)
|
static int cli_io_handler_show_startup_logs(struct appctx *appctx)
|
||||||
{
|
{
|
||||||
struct stream_interface *si = appctx->owner;
|
struct stream_interface *si = appctx->owner;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user