改进HTTP访问日志格式
This commit is contained in:
@@ -101,6 +101,10 @@ struct tfe_stream_private
|
|||||||
|
|
||||||
/* KEYRING-ID */
|
/* KEYRING-ID */
|
||||||
unsigned keyring_id;
|
unsigned keyring_id;
|
||||||
|
|
||||||
|
/* ONLY FOR LOG */
|
||||||
|
evutil_socket_t log_fd_downstream;
|
||||||
|
evutil_socket_t log_fd_upstream;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void * __STREAM_LOGGER(struct tfe_stream_private * _stream)
|
static inline void * __STREAM_LOGGER(struct tfe_stream_private * _stream)
|
||||||
|
|||||||
@@ -318,6 +318,16 @@ static void __conn_private_destory_with_ssl(struct event_base * ev_base,
|
|||||||
return __conn_private_destory(conn);
|
return __conn_private_destory(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void __stream_bev_downstream_statcb(struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg)
|
||||||
|
{
|
||||||
|
struct tfe_stream_private * _stream = (struct tfe_stream_private *) arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __stream_bev_upstream_statcb(struct evbuffer *buffer, const struct evbuffer_cb_info *info, void *arg)
|
||||||
|
{
|
||||||
|
struct tfe_stream_private * _stream = (struct tfe_stream_private *) arg;
|
||||||
|
}
|
||||||
|
|
||||||
static void __stream_bev_passthrough_readcb(struct bufferevent * bev, void * arg)
|
static void __stream_bev_passthrough_readcb(struct bufferevent * bev, void * arg)
|
||||||
{
|
{
|
||||||
struct tfe_stream_private * _stream = (struct tfe_stream_private *) arg;
|
struct tfe_stream_private * _stream = (struct tfe_stream_private *) arg;
|
||||||
@@ -551,11 +561,13 @@ static void __stream_bev_writecb(struct bufferevent * bev, void * arg)
|
|||||||
struct tfe_conn_private ** ref_peer_conn{};
|
struct tfe_conn_private ** ref_peer_conn{};
|
||||||
struct ssl_stream ** ref_this_ssl_stream{};
|
struct ssl_stream ** ref_this_ssl_stream{};
|
||||||
|
|
||||||
|
const char * __str_dir = NULL;
|
||||||
if (__bev_dir(_stream, bev) == CONN_DIR_UPSTREAM)
|
if (__bev_dir(_stream, bev) == CONN_DIR_UPSTREAM)
|
||||||
{
|
{
|
||||||
ref_this_conn = &_stream->conn_upstream;
|
ref_this_conn = &_stream->conn_upstream;
|
||||||
ref_this_ssl_stream = &_stream->ssl_upstream;
|
ref_this_ssl_stream = &_stream->ssl_upstream;
|
||||||
ref_peer_conn = &_stream->conn_downstream;
|
ref_peer_conn = &_stream->conn_downstream;
|
||||||
|
__str_dir = "up";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (__bev_dir(_stream, bev) == CONN_DIR_DOWNSTREAM)
|
if (__bev_dir(_stream, bev) == CONN_DIR_DOWNSTREAM)
|
||||||
@@ -563,6 +575,7 @@ static void __stream_bev_writecb(struct bufferevent * bev, void * arg)
|
|||||||
ref_this_conn = &_stream->conn_downstream;
|
ref_this_conn = &_stream->conn_downstream;
|
||||||
ref_this_ssl_stream = &_stream->ssl_downstream;
|
ref_this_ssl_stream = &_stream->ssl_downstream;
|
||||||
ref_peer_conn = &_stream->conn_upstream;
|
ref_peer_conn = &_stream->conn_upstream;
|
||||||
|
__str_dir = "down";
|
||||||
}
|
}
|
||||||
|
|
||||||
struct evbuffer * __output_buffer = bufferevent_get_output(bev);
|
struct evbuffer * __output_buffer = bufferevent_get_output(bev);
|
||||||
@@ -573,6 +586,9 @@ static void __stream_bev_writecb(struct bufferevent * bev, void * arg)
|
|||||||
__conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream);
|
__conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream);
|
||||||
*ref_this_conn = NULL;
|
*ref_this_conn = NULL;
|
||||||
*ref_this_ssl_stream = NULL;
|
*ref_this_ssl_stream = NULL;
|
||||||
|
|
||||||
|
fprintf(stderr, "---- writecb ----, close this connection, "
|
||||||
|
"stream = %p, dir = %s\n", _stream, __str_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ref_peer_conn == NULL && *ref_this_conn == NULL)
|
if (*ref_peer_conn == NULL && *ref_this_conn == NULL)
|
||||||
@@ -624,7 +640,7 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void *
|
|||||||
__stream_bev_readcb(bev, arg);
|
__stream_bev_readcb(bev, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//fprintf(stderr, "---- eventcb ----, stream = %p, event = %x, dir = %s\n", _stream, events, __str_dir);
|
fprintf(stderr, "---- eventcb ----, stream = %p, event = %x, dir = %s\n", _stream, events, __str_dir);
|
||||||
goto __close_connection;
|
goto __close_connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,8 +662,8 @@ __close_connection:
|
|||||||
|
|
||||||
if (*ref_this_conn != NULL)
|
if (*ref_this_conn != NULL)
|
||||||
{
|
{
|
||||||
//fprintf(stderr, "---- eventcb ----, close this connection, "
|
fprintf(stderr, "---- eventcb ----, close this connection, "
|
||||||
// "stream = %p, event = %x, dir = %s\n", _stream, events, __str_dir);
|
"stream = %p, event = %x, dir = %s\n", _stream, events, __str_dir);
|
||||||
|
|
||||||
__conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream);
|
__conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream);
|
||||||
*ref_this_conn = NULL;
|
*ref_this_conn = NULL;
|
||||||
@@ -796,7 +812,11 @@ struct tfe_stream * tfe_stream_create(struct tfe_proxy * pxy, struct tfe_thread_
|
|||||||
|
|
||||||
void __stream_access_log_write(struct tfe_stream_private * stream)
|
void __stream_access_log_write(struct tfe_stream_private * stream)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(stream->stream_logger, RLOG_LV_INFO, "access", "%s", stream->str_stream_addr);
|
const char * str_passthrough = stream->passthough ? "PASSTHROUGH" : "-";
|
||||||
|
|
||||||
|
MESA_handle_runtime_log(stream->stream_logger, RLOG_LV_INFO, "access",
|
||||||
|
"%d %d %d %s %s", stream->log_fd_downstream, stream->log_fd_upstream, stream->keyring_id,
|
||||||
|
stream->str_stream_addr, str_passthrough);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tfe_stream_destory(struct tfe_stream_private * stream)
|
void tfe_stream_destory(struct tfe_stream_private * stream)
|
||||||
@@ -1005,6 +1025,8 @@ int tfe_stream_init_by_fds(struct tfe_stream * stream, evutil_socket_t fd_downst
|
|||||||
|
|
||||||
_stream->defer_fd_downstream = fd_downstream;
|
_stream->defer_fd_downstream = fd_downstream;
|
||||||
_stream->defer_fd_upstream = fd_upstream;
|
_stream->defer_fd_upstream = fd_upstream;
|
||||||
|
_stream->log_fd_downstream = fd_downstream;
|
||||||
|
_stream->log_fd_upstream = fd_upstream;
|
||||||
|
|
||||||
__stream_fd_option_setup(_stream, fd_downstream);
|
__stream_fd_option_setup(_stream, fd_downstream);
|
||||||
__stream_fd_option_setup(_stream, fd_upstream);
|
__stream_fd_option_setup(_stream, fd_upstream);
|
||||||
|
|||||||
@@ -1091,17 +1091,15 @@ void __write_access_log(struct http_session_private * hs_private)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Content Type */
|
/* Content Type */
|
||||||
const char * __str_cont_type = resp_spec ? resp_spec->content_type : "-";
|
const char * __str_cont_type = resp_spec ? resp_spec->content_type != NULL ? resp_spec->content_type : "-" : "-";
|
||||||
/* Content Length */
|
|
||||||
const char * __str_cont_length = resp_spec ? resp_spec->content_length : "-";
|
|
||||||
/* Content Encoding */
|
/* Content Encoding */
|
||||||
const char * __str_cont_encoding = resp_spec ? resp_spec->content_encoding : "-";
|
const char * __str_cont_encoding = resp_spec ? resp_spec->content_encoding != NULL ? resp_spec->content_encoding: "-" : "-";
|
||||||
/* Upgrade Tag */
|
/* Upgrade Tag */
|
||||||
const char * __str_upgrade = response->is_upgrade ? "UPGRADE" : "-";
|
const char * __str_upgrade = response ? response->is_upgrade ? "UPGRADE" : "-" : "-";
|
||||||
|
|
||||||
char * __access_log;
|
char * __access_log;
|
||||||
asprintf(&__access_log, "%s %s %s %s %s %s %s", __str_method,
|
asprintf(&__access_log, "%d %s %s HTTP/%d.%d %s %s %s %s", hs_private->hs_public.session_id, __str_method,
|
||||||
__str_url, __str_resp_code, __str_cont_type, __str_cont_length, __str_cont_encoding, __str_upgrade);
|
__str_url, request->major, request->minor, __str_resp_code, __str_cont_type, __str_cont_encoding, __str_upgrade);
|
||||||
|
|
||||||
const struct tfe_stream * stream = hs_private->hc_private->stream;
|
const struct tfe_stream * stream = hs_private->hc_private->stream;
|
||||||
tfe_stream_write_access_log(stream, RLOG_LV_INFO, "%s", __access_log);
|
tfe_stream_write_access_log(stream, RLOG_LV_INFO, "%s", __access_log);
|
||||||
|
|||||||
Reference in New Issue
Block a user